All of lore.kernel.org
 help / color / mirror / Atom feed
* re: md/bitmap: move some fields of 'struct bitmap' into a 'storage' substruct.
@ 2012-04-20 13:13 Dan Carpenter
  2012-04-23  0:10 ` NeilBrown
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-04-20 13:13 UTC (permalink / raw)
  To: neilb; +Cc: linux-raid

Hello NeilBrown,

This is a semi-automatic email about new static checker warnings.

The patch 9159d8a35d0a: "md/bitmap: move some fields of 'struct
bitmap' into a 'storage' substruct." from Apr 19, 2012, leads to the
following Smatch complaint:

drivers/md/bitmap.c:1212 bitmap_daemon_work()
	error: we previously assumed 'bitmap->storage.filemap' could be
	       null (see line 1145)

drivers/md/bitmap.c
  1144			bitmap->need_sync = 0;
  1145			if (bitmap->storage.filemap) {
                            ^^^^^^^^^^^^^^^^^^^^^^^
Renamed check.

  1146				sb = kmap_atomic(bitmap->storage.sb_page);
  1147				sb->events_cleared =
  1148					cpu_to_le64(bitmap->events_cleared);
  1149				kunmap_atomic(sb);
  1150				set_page_attr(bitmap, 0,
  1151					      BITMAP_PAGE_NEEDWRITE);
  1152			}
  1153		}

[snip]

  1210			if (test_and_clear_page_attr(bitmap, j,
  1211						     BITMAP_PAGE_NEEDWRITE)) {
  1212				write_page(bitmap, bitmap->storage.filemap[j], 0);
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
Renamed dereference.

  1213				if (!bitmap->storage.filemap)
                                     ^^^^^^^^^^^^^^^^^^^^^^^
Another check.

  1214					break;

Really, this isn't a new warning, it's just shows up as a new warning
because of the rename.  Still, I was curious about the check after the
dereference.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: md/bitmap: move some fields of 'struct bitmap' into a 'storage' substruct.
  2012-04-20 13:13 md/bitmap: move some fields of 'struct bitmap' into a 'storage' substruct Dan Carpenter
@ 2012-04-23  0:10 ` NeilBrown
  2012-04-23 10:17   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: NeilBrown @ 2012-04-23  0:10 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 2461 bytes --]

On Fri, 20 Apr 2012 16:13:36 +0300 Dan Carpenter <dan.carpenter@ORACLE.COM>
wrote:

> Hello NeilBrown,
> 
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 9159d8a35d0a: "md/bitmap: move some fields of 'struct
> bitmap' into a 'storage' substruct." from Apr 19, 2012, leads to the
> following Smatch complaint:
> 
> drivers/md/bitmap.c:1212 bitmap_daemon_work()
> 	error: we previously assumed 'bitmap->storage.filemap' could be
> 	       null (see line 1145)
> 
> drivers/md/bitmap.c
>   1144			bitmap->need_sync = 0;
>   1145			if (bitmap->storage.filemap) {
>                             ^^^^^^^^^^^^^^^^^^^^^^^
> Renamed check.
> 
>   1146				sb = kmap_atomic(bitmap->storage.sb_page);
>   1147				sb->events_cleared =
>   1148					cpu_to_le64(bitmap->events_cleared);
>   1149				kunmap_atomic(sb);
>   1150				set_page_attr(bitmap, 0,
>   1151					      BITMAP_PAGE_NEEDWRITE);
>   1152			}
>   1153		}
> 
> [snip]
> 
>   1210			if (test_and_clear_page_attr(bitmap, j,
>   1211						     BITMAP_PAGE_NEEDWRITE)) {
>   1212				write_page(bitmap, bitmap->storage.filemap[j], 0);
>                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
> Renamed dereference.

There is a relationship between storage.filemap and storage.file_pages.
If the later is 0, the former must be non-NULL.

This dereference only happens if file_pages > 0...  Maybe I should check
file_pages up above so as not to confuse smatch??

> 
>   1213				if (!bitmap->storage.filemap)
>                                      ^^^^^^^^^^^^^^^^^^^^^^^
> Another check.

Yes, that does look odd.  The check isn't needed any more and I have just
removed it.
Previously if write_page() got an error it would free the filemap.  At that
time there was locking here.
   spin_unlock
   write_page()
   spin_lock
   if (!bitmap->storage.filemap) ....

so it was more obvious that filemap could well change between the write_page
and the test.
When I change write_page to not free the filemap any more, I could remove the
locking.  But I didn't notice that I could remove the test as well.

New code will be in my for-next shortly.

Thanks,
NeilBrown


> 
>   1214					break;
> 
> Really, this isn't a new warning, it's just shows up as a new warning
> because of the rename.  Still, I was curious about the check after the
> dereference.
> 
> regards,
> dan carpenter


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: md/bitmap: move some fields of 'struct bitmap' into a 'storage' substruct.
  2012-04-23  0:10 ` NeilBrown
@ 2012-04-23 10:17   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-04-23 10:17 UTC (permalink / raw)
  To: NeilBrown; +Cc: linux-raid

On Mon, Apr 23, 2012 at 10:10:49AM +1000, NeilBrown wrote:
> On Fri, 20 Apr 2012 16:13:36 +0300 Dan Carpenter <dan.carpenter@ORACLE.COM>
> >   1210			if (test_and_clear_page_attr(bitmap, j,
> >   1211						     BITMAP_PAGE_NEEDWRITE)) {
> >   1212				write_page(bitmap, bitmap->storage.filemap[j], 0);
> >                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Renamed dereference.
> 
> There is a relationship between storage.filemap and storage.file_pages.
> If the later is 0, the former must be non-NULL.
> 
> This dereference only happens if file_pages > 0...  Maybe I should check
> file_pages up above so as not to confuse smatch??
> 

False positives are not really a problem.  I only look at new
warnings.  My dream is that someday Smatch will be able to figure
out the code flow as it is.

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-23 10:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20 13:13 md/bitmap: move some fields of 'struct bitmap' into a 'storage' substruct Dan Carpenter
2012-04-23  0:10 ` NeilBrown
2012-04-23 10:17   ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.