[PATCH] jffs, clang: avoid some warnings of used uninitialized ptr

Daniel Hellstrom daniel at gaisler.com
Fri Oct 5 10:44:01 UTC 2018


On 2018-10-05 09:41, Sebastian Huber wrote:
> On 05/10/2018 09:38, Daniel Hellstrom wrote:
>>
>> On 2018-10-05 09:34, Sebastian Huber wrote:
>>> On 05/10/2018 09:25, Daniel Hellstrom wrote:
>>>> On 2018-10-05 09:12, Sebastian Huber wrote:
>>>>> On 05/10/2018 08:57, Daniel Hellstrom wrote:
>>>>>> This fixes the following test failures on LEON3 UP/SMP when
>>>>>> built using clang compiler:
>>>>>>   * fsjffs2gc01
>>>>>>   * jffs2_fserror
>>>>>>   * jffs2_fspermission
>>>>>>   * jffs2_fsrdwr
>>>>>>   * jffs2_fstime
>>>>>
>>>>> The problem is probably in the 
>>>>> rbtree_postorder_for_each_entry_safe(). Coverity Scan has also an 
>>>>> issue with this macro. It is on my todo list. Please do not check 
>>>>> in this patch.
>>>> Ok I will not push it. Yes I was also thinking so. To use 
>>>> offsetof() macro could be an option maybe, however the node type 
>>>> input is not known to the rbtree_postorder_for_each_entry_safe() 
>>>> function even though it only used from jffs2 code. 
>>>
>>> The Linux code uses typeof. We could do this also:
>>>
>>> diff --git a/cpukit/include/linux/rbtree.h 
>>> b/cpukit/include/linux/rbtree.h
>>> index 53c777e8c1..8fc575240f 100644
>>> --- a/cpukit/include/linux/rbtree.h
>>> +++ b/cpukit/include/linux/rbtree.h
>>> @@ -126,12 +126,12 @@ static inline struct rb_node *rb_parent( 
>>> struct rb_node *node )
>>>    for ( \
>>>      node = _RBTree_Postorder_first( \
>>>        (RBTree_Control *) root, \
>>> -      (size_t) ( (char *) &node->field - (char *) node ) \
>>> +      offsetof( __typeof__( *node ), field ) \
>>>      ); \
>>>      node != NULL && ( \
>>>        next = _RBTree_Postorder_next( \
>>>          &node->field, \
>>> -        (size_t) ( (char *) &node->field - (char *) node ) \
>>> +        offsetof( __typeof__( *node ), field ) \
>>>        ), \
>>>        node != NULL \
>>>      ); \
>>>
>>> It shouldn't be a big problem since at least GCC and clang supports 
>>> it. It is also a standard C++ operator. It is already used in
>>>
>>> cpukit/libfs/src/jffs2/include/linux/list.h
>>
>> Ok, I will give it a try.
>>
>
> Thanks, please try this patch:
>
> https://lists.rtems.org/pipermail/devel/2018-October/023181.html

Yes I can confirm it fixed all the 5 tests on gr712rc with clang. It 
also removed the two warnings in jffs2 code related.

I have updated my patch to only include the third warning fix then:

---
  cpukit/libfs/src/jffs2/src/readinode.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libfs/src/jffs2/src/readinode.c 
b/cpukit/libfs/src/jffs2/src/readinode.c
index 519b0d6..ecdf335 100644
--- a/cpukit/libfs/src/jffs2/src/readinode.c
+++ b/cpukit/libfs/src/jffs2/src/readinode.c
@@ -35,7 +35,7 @@ static int check_node_data(struct jffs2_sb_info *c, 
struct jffs2_tmp_dnode_info
      struct jffs2_raw_node_ref *ref = tn->fn->raw;
      int err = 0, pointed = 0;
      struct jffs2_eraseblock *jeb;
-    unsigned char *buffer;
+    unsigned char *buffer = NULL;
      uint32_t crc, ofs, len;
      size_t retlen;

-- 




More information about the devel mailing list