linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: legacy: fix redundant initialization warnings from cppcheck
@ 2020-04-03 13:16 Masahiro Yamada
  2020-04-03 14:42 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2020-04-03 13:16 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: Greg KH, Masahiro Yamada, Corentin Labbe, David Howells,
	Felipe Balbi, Peter Zijlstra (Intel),
	Thomas Gleixner, linux-kernel

Fix the following cppcheck warnings:

drivers/usb/gadget/legacy/inode.c:1364:8: style: Redundant initialization for 'value'. The initialized value is overwritten$
 value = -EOPNOTSUPP;
       ^
drivers/usb/gadget/legacy/inode.c:1331:15: note: value is initialized
 int    value = -EOPNOTSUPP;
              ^
drivers/usb/gadget/legacy/inode.c:1364:8: note: value is overwritten
 value = -EOPNOTSUPP;
       ^
drivers/usb/gadget/legacy/inode.c:1817:8: style: Redundant initialization for 'value'. The initialized value is overwritten$
 value = -EINVAL;
       ^
drivers/usb/gadget/legacy/inode.c:1787:18: note: value is initialized
 ssize_t   value = len, length = len;
                 ^
drivers/usb/gadget/legacy/inode.c:1817:8: note: value is overwritten
 value = -EINVAL;
       ^

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

I do not think this is my fault because the addressed commit did not
touch this file, but the kbuild test robot sent me this report somehow:

  https://lkml.org/lkml/2020/4/3/395

Anyway, the warnings are real, so I removed the redundant assignments.
I re-ran cppcheck and confirmed the warnings have been fixed.


 drivers/usb/gadget/legacy/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index aa0de9e35afa..3afddd3bea6e 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1361,7 +1361,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 
 	req->buf = dev->rbuf;
 	req->context = NULL;
-	value = -EOPNOTSUPP;
 	switch (ctrl->bRequest) {
 
 	case USB_REQ_GET_DESCRIPTOR:
@@ -1784,7 +1783,7 @@ static ssize_t
 dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 {
 	struct dev_data		*dev = fd->private_data;
-	ssize_t			value = len, length = len;
+	ssize_t			value, length = len;
 	unsigned		total;
 	u32			tag;
 	char			*kbuf;
-- 
2.17.1


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

* Re: [PATCH] usb: gadget: legacy: fix redundant initialization warnings from cppcheck
  2020-04-03 13:16 [PATCH] usb: gadget: legacy: fix redundant initialization warnings from cppcheck Masahiro Yamada
@ 2020-04-03 14:42 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2020-04-03 14:42 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Felipe Balbi, linux-usb, Greg KH, Corentin Labbe, David Howells,
	Felipe Balbi, Peter Zijlstra (Intel),
	Thomas Gleixner, linux-kernel

On Fri, 3 Apr 2020, Masahiro Yamada wrote:

> Fix the following cppcheck warnings:
> 
> drivers/usb/gadget/legacy/inode.c:1364:8: style: Redundant initialization for 'value'. The initialized value is overwritten$
>  value = -EOPNOTSUPP;
>        ^
> drivers/usb/gadget/legacy/inode.c:1331:15: note: value is initialized
>  int    value = -EOPNOTSUPP;
>               ^
> drivers/usb/gadget/legacy/inode.c:1364:8: note: value is overwritten
>  value = -EOPNOTSUPP;
>        ^
> drivers/usb/gadget/legacy/inode.c:1817:8: style: Redundant initialization for 'value'. The initialized value is overwritten$
>  value = -EINVAL;
>        ^
> drivers/usb/gadget/legacy/inode.c:1787:18: note: value is initialized
>  ssize_t   value = len, length = len;
>                  ^
> drivers/usb/gadget/legacy/inode.c:1817:8: note: value is overwritten
>  value = -EINVAL;
>        ^
> 
> Reported-by: kbuild test robot <lkp@intel.com>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
> I do not think this is my fault because the addressed commit did not
> touch this file, but the kbuild test robot sent me this report somehow:
> 
>   https://lkml.org/lkml/2020/4/3/395
> 
> Anyway, the warnings are real, so I removed the redundant assignments.
> I re-ran cppcheck and confirmed the warnings have been fixed.
> 
> 
>  drivers/usb/gadget/legacy/inode.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
> index aa0de9e35afa..3afddd3bea6e 100644
> --- a/drivers/usb/gadget/legacy/inode.c
> +++ b/drivers/usb/gadget/legacy/inode.c
> @@ -1361,7 +1361,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
>  
>  	req->buf = dev->rbuf;
>  	req->context = NULL;
> -	value = -EOPNOTSUPP;
>  	switch (ctrl->bRequest) {
>  
>  	case USB_REQ_GET_DESCRIPTOR:
> @@ -1784,7 +1783,7 @@ static ssize_t
>  dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
>  {
>  	struct dev_data		*dev = fd->private_data;
> -	ssize_t			value = len, length = len;
> +	ssize_t			value, length = len;
>  	unsigned		total;
>  	u32			tag;
>  	char			*kbuf;

Acked-by: Alan Stern <stern@rowland.harvard.edu>


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

end of thread, other threads:[~2020-04-03 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 13:16 [PATCH] usb: gadget: legacy: fix redundant initialization warnings from cppcheck Masahiro Yamada
2020-04-03 14:42 ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).