ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb()
PATCH v2 1/1 ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.
Also, address the following sparse warnings:sound/usb/mixer_scarlett_gen2.c:1064:28: warning: using sizeof on a flexible structure sound/usb/mixer_scarlett_gen2.c:1065:29: warning: using sizeof on a flexible structure
---
Changes in v2:
- Use correct format specifier %zu for type size_t argument.
sound/usb/mixer_scarlett_gen2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/usb/mixer_scarlett_gen2.c +3 -3
@@ -1061,9 +1061,9 @@ static int scarlett2_usb( {struct scarlett2_data *private = mixer->private_data;struct usb_device *dev = mixer->chip->dev; -u16 req_buf_size =sizeof (struct scarlett2_usb_packet ) + req_size; -u16 resp_buf_size =sizeof (struct scarlett2_usb_packet ) + resp_size;struct scarlett2_usb_packet *req, *resp =NULL ; +size_t req_buf_size =struct_size (req, data, req_size); +size_t resp_buf_size =struct_size (resp, data, resp_size);int err; req =kmalloc (req_buf_size,GFP_KERNEL );
@@ -1111,7 +1111,7 @@ static int scarlett2_usb(usb_audio_err ( mixer->chip,"Scarlett Gen 2/3 USB response result cmd %x was %d " -"expected %d\n" , +"expected %zu\n" , cmd, err, resp_buf_size); err = -EINVAL ; goto unlock;
Signature · 1 line
2.27.0
Quoted 10 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.Also, address the following sparse warnings:
sound/usb/mixer_scarlett_gen2.c:1064:28: warning: using sizeof on a flexible structuresound/usb/mixer_scarlett_gen2.c:1065:29: warning: using sizeof on a flexible structure
Looks good to me!
Quoted 35 lines
---
Changes in v2:
- Use correct format specifier %zu for typesize_targument.sound/usb/mixer_scarlett_gen2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)sound/usb/mixer_scarlett_gen2.c +3
-3@@ -1061,9 +1061,9 @@ static int scarlett2_usb( {struct scarlett2_data *private = mixer->private_data;struct usb_device *dev = mixer->chip->dev; -u16 req_buf_size =sizeof (struct scarlett2_usb_packet ) + req_size; -u16 resp_buf_size =sizeof (struct scarlett2_usb_packet ) + resp_size;struct scarlett2_usb_packet *req, *resp =NULL ; +size_t req_buf_size =struct_size (req, data, req_size); +size_t resp_buf_size =struct_size (resp, data, resp_size);int err; req =kmalloc (req_buf_size,GFP_KERNEL );@@ -1111,7 +1111,7 @@ static int scarlett2_usb(usb_audio_err ( mixer->chip,"Scarlett Gen 2/3 USB response result cmd %x was %d " -"expected %d\n" , +"expected %zu\n" , cmd, err, resp_buf_size); err = -EINVAL ; goto unlock;Signature · 1 line
2.27.0
Signature · 1 line
Kees Cook
Quoted 9 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.Also, address the following sparse warnings:
sound/usb/mixer_scarlett_gen2.c:1064:28: warning: using sizeof on a flexible structuresound/usb/mixer_scarlett_gen2.c:1065:29: warning: using sizeof on a flexible structure
Quoted 5 lines
---
Changes in v2:
- Use correct format specifier %zu for typesize_targument.
Applied now. Thanks.
Takashi