diff mbox series

[next] ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb()

Message ID 20220120001423.GA69878@embeddedor (mailing list archive)
State Superseded
Headers show
Series [next] ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb() | expand

Commit Message

Gustavo A. R. Silva Jan. 20, 2022, 12:14 a.m. UTC
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

Link: https://github.com/KSPP/linux/issues/160
Link: https://github.com/KSPP/linux/issues/174
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 sound/usb/mixer_scarlett_gen2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

kernel test robot Jan. 20, 2022, 3:28 a.m. UTC | #1
Hi "Gustavo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on v5.16 next-20220118]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Gustavo-A-R-Silva/ALSA-usb-audio-scarlett2-Use-struct_size-helper-in-scarlett2_usb/20220120-080908
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20220120/202201201043.0reWtM98-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/1696152f12c0a7d23ccd5e228f9d08f7bd2da83a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Gustavo-A-R-Silva/ALSA-usb-audio-scarlett2-Use-struct_size-helper-in-scarlett2_usb/20220120-080908
        git checkout 1696152f12c0a7d23ccd5e228f9d08f7bd2da83a
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=m68k SHELL=/bin/bash sound/usb/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from include/linux/usb/ch9.h:36,
                    from include/linux/usb.h:6,
                    from sound/usb/mixer_scarlett_gen2.c:126:
   sound/usb/mixer_scarlett_gen2.c: In function 'scarlett2_usb':
>> sound/usb/mixer_scarlett_gen2.c:1113:25: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
    1113 |                         "Scarlett Gen 2/3 USB response result cmd %x was %d "
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:144:56: note: in expansion of macro 'dev_fmt'
     144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                        ^~~~~~~
   sound/usb/usbaudio.h:67:9: note: in expansion of macro 'dev_err'
      67 |         dev_err(&(chip)->dev->dev, fmt, ##args)
         |         ^~~~~~~
   sound/usb/mixer_scarlett_gen2.c:1111:17: note: in expansion of macro 'usb_audio_err'
    1111 |                 usb_audio_err(
         |                 ^~~~~~~~~~~~~


vim +1113 sound/usb/mixer_scarlett_gen2.c

1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1056  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1057  /* Send a proprietary format request to the Scarlett interface */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1058  static int scarlett2_usb(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1059  	struct usb_mixer_interface *mixer, u32 cmd,
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1060  	void *req_data, u16 req_size, void *resp_data, u16 resp_size)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1061  {
e46f2195c86b00 Geoffrey D. Bennett 2021-06-21  1062  	struct scarlett2_data *private = mixer->private_data;
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1063  	struct usb_device *dev = mixer->chip->dev;
b677b6c6d82248 Geoffrey D. Bennett 2021-06-21  1064  	struct scarlett2_usb_packet *req, *resp = NULL;
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1065  	size_t req_buf_size = struct_size(req, data, req_size);
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1066  	size_t resp_buf_size = struct_size(resp, data, resp_size);
b677b6c6d82248 Geoffrey D. Bennett 2021-06-21  1067  	int err;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1068  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1069  	req = kmalloc(req_buf_size, GFP_KERNEL);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1070  	if (!req) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1071  		err = -ENOMEM;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1072  		goto error;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1073  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1074  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1075  	resp = kmalloc(resp_buf_size, GFP_KERNEL);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1076  	if (!resp) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1077  		err = -ENOMEM;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1078  		goto error;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1079  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1080  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1081  	mutex_lock(&private->usb_mutex);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1082  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1083  	/* build request message and send it */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1084  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1085  	scarlett2_fill_request_header(private, req, cmd, req_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1086  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1087  	if (req_size)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1088  		memcpy(req->data, req_data, req_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1089  
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1090  	err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1091  			       req, req_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1092  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1093  	if (err != req_buf_size) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1094  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1095  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23  1096  			"Scarlett Gen 2/3 USB request result cmd %x was %d\n",
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1097  			cmd, err);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1098  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1099  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1100  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1101  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1102  	/* send a second message to get the response */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1103  
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1104  	err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1105  			       SCARLETT2_USB_CMD_RESP,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1106  			       resp, resp_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1107  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1108  	/* validate the response */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1109  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1110  	if (err != resp_buf_size) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1111  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1112  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23 @1113  			"Scarlett Gen 2/3 USB response result cmd %x was %d "
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1114  			"expected %lu\n",
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1115  			cmd, err, resp_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1116  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1117  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1118  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1119  
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1120  	/* cmd/seq/size should match except when initialising
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1121  	 * seq sent = 1, response = 0
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1122  	 */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1123  	if (resp->cmd != req->cmd ||
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1124  	    (resp->seq != req->seq &&
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1125  		(le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1126  	    resp_size != le16_to_cpu(resp->size) ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1127  	    resp->error ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1128  	    resp->pad) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1129  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1130  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23  1131  			"Scarlett Gen 2/3 USB invalid response; "
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1132  			   "cmd tx/rx %d/%d seq %d/%d size %d/%d "
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1133  			   "error %d pad %d\n",
d8f489355cff55 Takashi Iwai        2020-02-01  1134  			le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1135  			le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1136  			resp_size, le16_to_cpu(resp->size),
d8f489355cff55 Takashi Iwai        2020-02-01  1137  			le32_to_cpu(resp->error),
d8f489355cff55 Takashi Iwai        2020-02-01  1138  			le32_to_cpu(resp->pad));
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1139  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1140  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1141  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1142  
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1143  	if (resp_data && resp_size > 0)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1144  		memcpy(resp_data, resp->data, resp_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1145  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1146  unlock:
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1147  	mutex_unlock(&private->usb_mutex);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1148  error:
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1149  	kfree(req);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1150  	kfree(resp);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1151  	return err;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1152  }
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1153  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Jan. 20, 2022, 4:29 a.m. UTC | #2
Hi "Gustavo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on v5.16 next-20220118]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Gustavo-A-R-Silva/ALSA-usb-audio-scarlett2-Use-struct_size-helper-in-scarlett2_usb/20220120-080908
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: i386-randconfig-a003-20220117 (https://download.01.org/0day-ci/archive/20220120/202201201212.O8wvhLQc-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project f7b7138a62648f4019c55e4671682af1f851f295)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/1696152f12c0a7d23ccd5e228f9d08f7bd2da83a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Gustavo-A-R-Silva/ALSA-usb-audio-scarlett2-Use-struct_size-helper-in-scarlett2_usb/20220120-080908
        git checkout 1696152f12c0a7d23ccd5e228f9d08f7bd2da83a
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash sound/usb/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> sound/usb/mixer_scarlett_gen2.c:1115:14: warning: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat]
                           cmd, err, resp_buf_size);
                                     ^~~~~~~~~~~~~
   sound/usb/usbaudio.h:67:36: note: expanded from macro 'usb_audio_err'
           dev_err(&(chip)->dev->dev, fmt, ##args)
                                      ~~~    ^~~~
   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
           dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
                                                                  ~~~     ^~~~~~~~~~~
   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
                   _p_func(dev, fmt, ##__VA_ARGS__);                       \
                                ~~~    ^~~~~~~~~~~
   1 warning generated.


vim +1115 sound/usb/mixer_scarlett_gen2.c

1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1056  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1057  /* Send a proprietary format request to the Scarlett interface */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1058  static int scarlett2_usb(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1059  	struct usb_mixer_interface *mixer, u32 cmd,
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1060  	void *req_data, u16 req_size, void *resp_data, u16 resp_size)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1061  {
e46f2195c86b00 Geoffrey D. Bennett 2021-06-21  1062  	struct scarlett2_data *private = mixer->private_data;
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1063  	struct usb_device *dev = mixer->chip->dev;
b677b6c6d82248 Geoffrey D. Bennett 2021-06-21  1064  	struct scarlett2_usb_packet *req, *resp = NULL;
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1065  	size_t req_buf_size = struct_size(req, data, req_size);
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1066  	size_t resp_buf_size = struct_size(resp, data, resp_size);
b677b6c6d82248 Geoffrey D. Bennett 2021-06-21  1067  	int err;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1068  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1069  	req = kmalloc(req_buf_size, GFP_KERNEL);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1070  	if (!req) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1071  		err = -ENOMEM;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1072  		goto error;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1073  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1074  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1075  	resp = kmalloc(resp_buf_size, GFP_KERNEL);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1076  	if (!resp) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1077  		err = -ENOMEM;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1078  		goto error;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1079  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1080  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1081  	mutex_lock(&private->usb_mutex);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1082  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1083  	/* build request message and send it */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1084  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1085  	scarlett2_fill_request_header(private, req, cmd, req_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1086  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1087  	if (req_size)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1088  		memcpy(req->data, req_data, req_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1089  
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1090  	err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1091  			       req, req_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1092  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1093  	if (err != req_buf_size) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1094  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1095  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23  1096  			"Scarlett Gen 2/3 USB request result cmd %x was %d\n",
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1097  			cmd, err);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1098  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1099  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1100  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1101  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1102  	/* send a second message to get the response */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1103  
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1104  	err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1105  			       SCARLETT2_USB_CMD_RESP,
1f7fa6e5afbf20 Geoffrey D. Bennett 2021-06-22  1106  			       resp, resp_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1107  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1108  	/* validate the response */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1109  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1110  	if (err != resp_buf_size) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1111  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1112  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23  1113  			"Scarlett Gen 2/3 USB response result cmd %x was %d "
1696152f12c0a7 Gustavo A. R. Silva 2022-01-19  1114  			"expected %lu\n",
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22 @1115  			cmd, err, resp_buf_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1116  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1117  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1118  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1119  
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1120  	/* cmd/seq/size should match except when initialising
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1121  	 * seq sent = 1, response = 0
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1122  	 */
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1123  	if (resp->cmd != req->cmd ||
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1124  	    (resp->seq != req->seq &&
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1125  		(le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1126  	    resp_size != le16_to_cpu(resp->size) ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1127  	    resp->error ||
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1128  	    resp->pad) {
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1129  		usb_audio_err(
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1130  			mixer->chip,
4be47798d76e6e Geoffrey D. Bennett 2021-06-23  1131  			"Scarlett Gen 2/3 USB invalid response; "
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1132  			   "cmd tx/rx %d/%d seq %d/%d size %d/%d "
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1133  			   "error %d pad %d\n",
d8f489355cff55 Takashi Iwai        2020-02-01  1134  			le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1135  			le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1136  			resp_size, le16_to_cpu(resp->size),
d8f489355cff55 Takashi Iwai        2020-02-01  1137  			le32_to_cpu(resp->error),
d8f489355cff55 Takashi Iwai        2020-02-01  1138  			le32_to_cpu(resp->pad));
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1139  		err = -EINVAL;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1140  		goto unlock;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1141  	}
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1142  
acf91b8122c7f6 Geoffrey D. Bennett 2021-06-22  1143  	if (resp_data && resp_size > 0)
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1144  		memcpy(resp_data, resp->data, resp_size);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1145  
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1146  unlock:
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1147  	mutex_unlock(&private->usb_mutex);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1148  error:
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1149  	kfree(req);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1150  	kfree(resp);
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1151  	return err;
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1152  }
9e4d5c1be21f0c Geoffrey D. Bennett 2019-07-29  1153  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 53ebabf42472..311413f015f0 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -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 %lu\n",
 			cmd, err, resp_buf_size);
 		err = -EINVAL;
 		goto unlock;