diff mbox series

[v3,1/4] usb: gadget: f_mass_storage: fix warning of -Werror=unused-but-set-variable

Message ID 1652097288-19909-2-git-send-email-quic_linyyuan@quicinc.com (mailing list archive)
State New, archived
Headers show
Series usb: gadget: update DECLARE_USB_FUNCTION(_INIT) macro | expand

Commit Message

Linyu Yuan May 9, 2022, 11:54 a.m. UTC
When add gcc W=1 compile flag, it report following error,
In function 'invalidate_sub':
error: variable 'rc' set but not used [-Werror=unused-but-set-variable],

Add a __maybe_unused property.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
---
v3: new add

 drivers/usb/gadget/function/f_mass_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Greg KH May 9, 2022, 12:48 p.m. UTC | #1
On Mon, May 09, 2022 at 07:54:45PM +0800, Linyu Yuan wrote:
> When add gcc W=1 compile flag, it report following error,
> In function 'invalidate_sub':
> error: variable 'rc' set but not used [-Werror=unused-but-set-variable],
> 
> Add a __maybe_unused property.
> 
> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
> ---
> v3: new add
> 
>  drivers/usb/gadget/function/f_mass_storage.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
> index 3a77bca..a688538 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -926,7 +926,7 @@ static void invalidate_sub(struct fsg_lun *curlun)
>  {
>  	struct file	*filp = curlun->filp;
>  	struct inode	*inode = file_inode(filp);
> -	unsigned long	rc;
> +	unsigned long	__maybe_unused rc;

That is almost never the correct solution here, sorry.  Fix this up
properly.

And W=1 really is not a valid thing to care about, right?

thanks,

>  	rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);

Why not properly handle the error?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 3a77bca..a688538 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -926,7 +926,7 @@  static void invalidate_sub(struct fsg_lun *curlun)
 {
 	struct file	*filp = curlun->filp;
 	struct inode	*inode = file_inode(filp);
-	unsigned long	rc;
+	unsigned long	__maybe_unused rc;
 
 	rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
 	VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);