diff mbox

[U-Boot,2/3] usb:composite: clear the whole common buffer

Message ID 1402320540-17058-3-git-send-email-jeroen@myspectrum.nl
State Accepted
Delegated to: Marek Vasut
Headers show

Commit Message

Jeroen Hofstee June 9, 2014, 1:28 p.m. UTC
Since the struct fsg_common is calloced, reset it completely
with zero's when reused. While at it, make checkpatch happy.

cc: Lukasz Majewski <l.majewski@samsung.com>
cc: Piotr Wilczek <p.wilczek@samsung.com>
cc: Kyungmin Park <kyungmin.park@samsung.com>
cc: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
---
drivers/usb/gadget/f_mass_storage.c:2470:28: warning: 'memset' call
operates on objects of type 'struct fsg_common' while the size is
based on a different type 'struct fsg_common *' [-Wsizeof-pointer-memaccess]
                memset(common, 0, sizeof common);

Note: There is another warning worth mentioning, but I don't
know what the correct behaviour should be.

drivers/usb/gadget/f_mass_storage.c:1153:6: warning: variable
'sdinfo' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        if (!curlun) {          /* Unsupported LUNs are okay */
            ^~~~~~~
drivers/usb/gadget/f_mass_storage.c:1168:21: note: uninitialized use occurs here
        put_unaligned_be32(sdinfo, &buf[3]);    /* Sense information */
---
 drivers/usb/gadget/f_mass_storage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Marek Vasut June 9, 2014, 5:59 p.m. UTC | #1
On Monday, June 09, 2014 at 03:28:59 PM, Jeroen Hofstee wrote:
> Since the struct fsg_common is calloced, reset it completely
> with zero's when reused. While at it, make checkpatch happy.
> 
> cc: Lukasz Majewski <l.majewski@samsung.com>
> cc: Piotr Wilczek <p.wilczek@samsung.com>
> cc: Kyungmin Park <kyungmin.park@samsung.com>
> cc: Marek Vasut <marek.vasut@gmail.com>
> Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

Acked-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
Ɓukasz Majewski June 10, 2014, 6:47 a.m. UTC | #2
Hi Jeroen,

> Since the struct fsg_common is calloced, reset it completely
> with zero's when reused. While at it, make checkpatch happy.
> 
> cc: Lukasz Majewski <l.majewski@samsung.com>
> cc: Piotr Wilczek <p.wilczek@samsung.com>
> cc: Kyungmin Park <kyungmin.park@samsung.com>
> cc: Marek Vasut <marek.vasut@gmail.com>
> Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
> ---
> drivers/usb/gadget/f_mass_storage.c:2470:28: warning: 'memset' call
> operates on objects of type 'struct fsg_common' while the size is
> based on a different type 'struct fsg_common
> *' [-Wsizeof-pointer-memaccess] memset(common, 0, sizeof common);
> 
> Note: There is another warning worth mentioning, but I don't
> know what the correct behaviour should be.
> 
> drivers/usb/gadget/f_mass_storage.c:1153:6: warning: variable
> 'sdinfo' is used uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized] if (!curlun) {          /* Unsupported
> LUNs are okay */ ^~~~~~~
> drivers/usb/gadget/f_mass_storage.c:1168:21: note: uninitialized use
> occurs here put_unaligned_be32(sdinfo, &buf[3]);    /* Sense
> information */ ---
>  drivers/usb/gadget/f_mass_storage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_mass_storage.c
> b/drivers/usb/gadget/f_mass_storage.c index 6374bb9..f274d96 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -2462,12 +2462,12 @@ static struct fsg_common
> *fsg_common_init(struct fsg_common *common, 
>  	/* Allocate? */
>  	if (!common) {
> -		common = calloc(sizeof *common, 1);
> +		common = calloc(sizeof(*common), 1);
>  		if (!common)
>  			return ERR_PTR(-ENOMEM);
>  		common->free_storage_on_release = 1;
>  	} else {
> -		memset(common, 0, sizeof common);
> +		memset(common, 0, sizeof(*common));
>  		common->free_storage_on_release = 0;
>  	}
>  

Acked-by: Lukasz Majewski <l.majewski@samsung.com>
diff mbox

Patch

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 6374bb9..f274d96 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2462,12 +2462,12 @@  static struct fsg_common *fsg_common_init(struct fsg_common *common,
 
 	/* Allocate? */
 	if (!common) {
-		common = calloc(sizeof *common, 1);
+		common = calloc(sizeof(*common), 1);
 		if (!common)
 			return ERR_PTR(-ENOMEM);
 		common->free_storage_on_release = 1;
 	} else {
-		memset(common, 0, sizeof common);
+		memset(common, 0, sizeof(*common));
 		common->free_storage_on_release = 0;
 	}