Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: liuh <liuhuan01@kylinos.cn>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] btrfs-progs: receive: fix unused variable warning without LZO
Date: Wed, 30 Sep 2026 14:17:42 +0800	[thread overview]
Message-ID: <d00a9825-4bde-444c-96ca-c70a73979d6f@kylinos.cn> (raw)
In-Reply-To: <dc67e026-1af8-44e6-adc6-f4c2e398f93e@suse.com>


在 2026/9/30 12:59, Qu Wenruo 写道:
>
>
> 在 2026/9/30 11:51, liuh0329 写道:
>> When btrfs-progs is built without LZO support, sector_shift is still
>> declared in decompress_and_write(), while all its uses are guarded by
>> COMPRESSION_LZO. This results in an unused variable warning.
>>
>> Move the sector_shift declaration to the LZO-specific code path so it is
>> only declared when LZO support is enabled.
>>
>> Fixes: 345731fff32d ("btrfs-progs: receive: optional build for lzo, 
>> zstd")
>> Signed-off-by: liuh0329 <liuhuan01@kylinos.cn>
>>
>> ---
>> Changes in v2:
>> - Move sector_shift declaration to its only usage, as suggested by Qu 
>> Wenruo.
>> - Add a local scope for sector_shift.
>>
>>   cmds/receive.c | 18 ++++++++++--------
>>   1 file changed, 10 insertions(+), 8 deletions(-)
>>
>> diff --git a/cmds/receive.c b/cmds/receive.c
>> index 49103ea3..02c864a6 100644
>> --- a/cmds/receive.c
>> +++ b/cmds/receive.c
>> @@ -1186,7 +1186,6 @@ static int decompress_and_write(struct 
>> btrfs_receive *rctx,
>>   {
>>       int ret = 0;
>>       char *unencoded_data;
>> -    int sector_shift = 0;
>>       u64 written = 0;
>>         unencoded_data = calloc(unencoded_len, 1);
>> @@ -1220,13 +1219,16 @@ static int decompress_and_write(struct 
>> btrfs_receive *rctx,
>>       case BTRFS_ENCODED_IO_COMPRESSION_LZO_32K:
>>       case BTRFS_ENCODED_IO_COMPRESSION_LZO_64K:
>>   #if COMPRESSION_LZO
>> -        sector_shift =
>> -            compression - BTRFS_ENCODED_IO_COMPRESSION_LZO_4K + 12;
>> -        ret = decompress_lzo(encoded_data, encoded_len, unencoded_data,
>> -                     unencoded_len, 1U << sector_shift);
>> -        if (ret)
>> -            goto out;
>> -        break;
>> +        {
>
> Why? Why not just simply do the following?

Thanks, that is simpler. I'll drop the extra scope and move the 
declaration directly to its only usage in v3.

> diff --git a/cmds/receive.c b/cmds/receive.c
> index 49103ea3eeea..f592a044801d 100644
> --- a/cmds/receive.c
> +++ b/cmds/receive.c
> @@ -1186,7 +1186,6 @@ static int decompress_and_write(struct 
> btrfs_receive *rctx,
>  {
>         int ret = 0;
>         char *unencoded_data;
> -       int sector_shift = 0;
>         u64 written = 0;
>
>         unencoded_data = calloc(unencoded_len, 1);
> @@ -1220,7 +1219,7 @@ static int decompress_and_write(struct 
> btrfs_receive *rctx,
>         case BTRFS_ENCODED_IO_COMPRESSION_LZO_32K:
>         case BTRFS_ENCODED_IO_COMPRESSION_LZO_64K:
>  #if COMPRESSION_LZO
> -               sector_shift =
> +               int sector_shift =
>                         compression - 
> BTRFS_ENCODED_IO_COMPRESSION_LZO_4K + 12;
>                 ret = decompress_lzo(encoded_data, encoded_len, 
> unencoded_data,
>                                      unencoded_len, 1U << sector_shift);
>
>
>> +            int sector_shift =
>> +                compression - BTRFS_ENCODED_IO_COMPRESSION_LZO_4K + 12;
>> +
>> +            ret = decompress_lzo(encoded_data, encoded_len, 
>> unencoded_data,
>> +                         unencoded_len, 1U << sector_shift);
>> +            if (ret)
>> +                goto out;
>> +            break;
>> +        }
>>   #else
>>           error("LZO compression for stream not compiled in");
>>           ret = -EOPNOTSUPP;
>

  reply	other threads:[~2026-09-30  6:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  7:14 [PATCH] btrfs-progs: receive: fix unused variable warning without LZO liuh0329
2026-09-29 10:37 ` Qu Wenruo
2026-09-30  2:21   ` [PATCH v2] " liuh0329
2026-09-30  4:59     ` Qu Wenruo
2026-09-30  6:17       ` liuh [this message]
2026-09-30  6:43       ` [PATCH v3] " liuh0329
2026-09-30  7:39         ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d00a9825-4bde-444c-96ca-c70a73979d6f@kylinos.cn \
    --to=liuhuan01@kylinos.cn \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox