All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block/snapshot: Fix compiler warning with -Wshadow=local
@ 2023-10-23 14:44 Thomas Huth
  2023-10-23 15:26 ` Markus Armbruster
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2023-10-23 14:44 UTC (permalink / raw)
  To: Hanna Reitz, Kevin Wolf, qemu-devel; +Cc: Markus Armbruster, qemu-block

No need to declare a new variable in the the inner code block
here, we can re-use the "ret" variable that has been declared
at the beginning of the function. With this change, the code
can now be successfully compiled with -Wshadow=local again.

Fixes: a32e781838 ("Mark bdrv_snapshot_fallback() and callers GRAPH_RDLOCK")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 block/snapshot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/snapshot.c b/block/snapshot.c
index 6e16eb803a..50adf5381e 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -629,8 +629,8 @@ int bdrv_all_goto_snapshot(const char *name,
     while (iterbdrvs) {
         BlockDriverState *bs = iterbdrvs->data;
         AioContext *ctx = bdrv_get_aio_context(bs);
-        int ret = 0;
         bool all_snapshots_includes_bs;
+        ret = 0;
 
         aio_context_acquire(ctx);
         bdrv_graph_rdlock_main_loop();
-- 
2.41.0



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

* Re: [PATCH] block/snapshot: Fix compiler warning with -Wshadow=local
  2023-10-23 14:44 [PATCH] block/snapshot: Fix compiler warning with -Wshadow=local Thomas Huth
@ 2023-10-23 15:26 ` Markus Armbruster
  2023-10-23 17:47   ` Thomas Huth
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2023-10-23 15:26 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Hanna Reitz, Kevin Wolf, qemu-devel, qemu-block

Thomas Huth <thuth@redhat.com> writes:

> No need to declare a new variable in the the inner code block
> here, we can re-use the "ret" variable that has been declared
> at the beginning of the function. With this change, the code
> can now be successfully compiled with -Wshadow=local again.
>
> Fixes: a32e781838 ("Mark bdrv_snapshot_fallback() and callers GRAPH_RDLOCK")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  block/snapshot.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/snapshot.c b/block/snapshot.c
> index 6e16eb803a..50adf5381e 100644
> --- a/block/snapshot.c
> +++ b/block/snapshot.c
> @@ -629,8 +629,8 @@ int bdrv_all_goto_snapshot(const char *name,
>      while (iterbdrvs) {
>          BlockDriverState *bs = iterbdrvs->data;
>          AioContext *ctx = bdrv_get_aio_context(bs);
> -        int ret = 0;
>          bool all_snapshots_includes_bs;

Blank line between declarations and statements, please.

I'm not sure we actually need the assignment.  Proving we don't looks
like a poor use of our time, though.

I recommend to move the assignment from here...

> +        ret = 0;
>  
>          aio_context_acquire(ctx);
>          bdrv_graph_rdlock_main_loop();
           all_snapshots_includes_bs = bdrv_all_snapshots_includes_bs(bs);
           bdrv_graph_rdunlock_main_loop();

... down to here.

           if (devices || all_snapshots_includes_bs) {
               ret = bdrv_snapshot_goto(bs, name, errp);
           }
           aio_context_release(ctx);
           if (ret < 0) {

We lose the symmetry with the other three while (iterbdrvs) loops.  Do
we care?



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

* Re: [PATCH] block/snapshot: Fix compiler warning with -Wshadow=local
  2023-10-23 15:26 ` Markus Armbruster
@ 2023-10-23 17:47   ` Thomas Huth
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2023-10-23 17:47 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Hanna Reitz, Kevin Wolf, qemu-devel, qemu-block

On 23/10/2023 17.26, Markus Armbruster wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
>> No need to declare a new variable in the the inner code block
>> here, we can re-use the "ret" variable that has been declared
>> at the beginning of the function. With this change, the code
>> can now be successfully compiled with -Wshadow=local again.
>>
>> Fixes: a32e781838 ("Mark bdrv_snapshot_fallback() and callers GRAPH_RDLOCK")
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   block/snapshot.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/block/snapshot.c b/block/snapshot.c
>> index 6e16eb803a..50adf5381e 100644
>> --- a/block/snapshot.c
>> +++ b/block/snapshot.c
>> @@ -629,8 +629,8 @@ int bdrv_all_goto_snapshot(const char *name,
>>       while (iterbdrvs) {
>>           BlockDriverState *bs = iterbdrvs->data;
>>           AioContext *ctx = bdrv_get_aio_context(bs);
>> -        int ret = 0;
>>           bool all_snapshots_includes_bs;
> 
> Blank line between declarations and statements, please.
> 
> I'm not sure we actually need the assignment.  Proving we don't looks
> like a poor use of our time, though.

I stared at the code for a while, and I think we don't urgently need it. But 
I'd still recommend to rather keep it to render the code more robust for 
future changes (imagine someone adds some code that changes ret in between, 
but does not return on negative values...)

> I recommend to move the assignment from here...
> 
>> +        ret = 0;
>>   
>>           aio_context_acquire(ctx);
>>           bdrv_graph_rdlock_main_loop();
>             all_snapshots_includes_bs = bdrv_all_snapshots_includes_bs(bs);
>             bdrv_graph_rdunlock_main_loop();
> 
> ... down to here.
> 
>             if (devices || all_snapshots_includes_bs) {
>                 ret = bdrv_snapshot_goto(bs, name, errp);
>             }

IMHO this would look best in my eyes:

         ret = (devices || all_snapshots_includes_bs) ?
               bdrv_snapshot_goto(bs, name, errp) : 0;

I'll send a v2 with this change.

>             aio_context_release(ctx);
>             if (ret < 0) {
> 
> We lose the symmetry with the other three while (iterbdrvs) loops.  Do
> we care?

No, at least I don't ;-)

  Thomas



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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 14:44 [PATCH] block/snapshot: Fix compiler warning with -Wshadow=local Thomas Huth
2023-10-23 15:26 ` Markus Armbruster
2023-10-23 17:47   ` Thomas Huth

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.