wusb: Use sizeof struct rather than pointer
PATCH 1/1 wusb: Use sizeof struct rather than pointer
The sizeof the struct should be used rather than sizeof the pointer
--- drivers/usb/wusbcore/security.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Unless I am mistaken?
drivers/usb/wusbcore/security.c +1 -1
@@ -213,7 +213,7 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc, result =usb_get_descriptor (usb_dev,USB_DT_SECURITY ,0 , secd,sizeof (struct usb_security_descriptor )); -if (result <sizeof (secd)) { +if (result <sizeof (*secd)) {dev_err (dev,"Can't read security descriptor or " "not enough data: %d\n" , result); goto out;
Quoted 14 lines · On Sat, 21 Nov 2009 19:51:14 +0100 Roel Kluin <[email protected]> wrote:
The sizeof the struct should be used rather than sizeof the pointer
Signed-off-by Roel Kluin <[email protected]>--- drivers/usb/wusbcore/security.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)Unless I am mistaken?
drivers/usb/wusbcore/security.c +0
-0
drivers/usb/wusbcore/security.c int wusb_dev_sec_add(struct wusbhc *wusbhc, · line 219
Quoted 8 lines
drivers/usb/wusbcore/security.c +1
-1@@ -213,7 +213,7 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc, result =usb_get_descriptor (usb_dev,USB_DT_SECURITY ,0 , secd,sizeof (struct usb_security_descriptor )); -if (result <sizeof (secd)) { +if (result <sizeof (*secd)) {dev_err (dev,"Can't read security descriptor or " "not enough data: %d\n" , result); goto out;
ick, code's a bit of a mess.
This:
drivers/usb/wusbcore/security.c renamed from drivers/usb/wusbcore/security.c~wusb-use-sizeof-struct-rather-than-pointer +4 -4
@@ -205,15 +205,15 @@ int wusb_dev_sec_add(struct wusbhc *wusbconst void *itr, *top;char buf[64 ]; - secd =kmalloc (sizeof (struct usb_security_descriptor ),GFP_KERNEL ); + secd =kmalloc (sizeof (*secd),GFP_KERNEL );if (secd ==NULL ) { result = -ENOMEM ; goto out; } - result =usb_get_descriptor (usb_dev,USB_DT_SECURITY , -0 , secd,sizeof (struct usb_security_descriptor )); -if (result <sizeof (secd)) { + result =usb_get_descriptor (usb_dev,USB_DT_SECURITY ,0 , secd, +sizeof (*secd)); +if (result <sizeof (*secd)) {dev_err (dev,"Can't read security descriptor or " "not enough data: %d\n" , result); goto out;
_
at least makes things consistent.
But I wonder if the code will still work. Because we then go on to do
secd_size = le16_to_cpu(secd->wTotalLength);
secd = krealloc(secd, secd_size, GFP_KERNEL);which implies (to me) that the thing we read from the device might indeed have been smaller than we expected, in which case the newly-fixed check will cause a failure.
That's probably not the case, but it needs checking by someone who knows what's going on here, please
Quoted 9 lines · Andrew Morton
But I wonder if the code will still work. Because we then go on to do
secd_size = le16_to_cpu(secd->wTotalLength); secd = krealloc(secd, secd_size, GFP_KERNEL);which implies (to me) that the thing we read from the device might indeed have been smaller than we expected, in which case the newly-fixed check will cause a failure.
We first read the security descriptor which tells use the total length of the security descriptor plus all the following encryption type descriptors. Your revised patch is fine.
David