@@ -317,9 +317,16 @@ static int tower_open (struct inode *inode, struct file *file)
317317 int subminor ;
318318 int retval = 0 ;
319319 struct usb_interface * interface ;
320- struct tower_reset_reply reset_reply ;
320+ struct tower_reset_reply * reset_reply ;
321321 int result ;
322322
323+ reset_reply = kmalloc (sizeof (* reset_reply ), GFP_KERNEL );
324+
325+ if (!reset_reply ) {
326+ retval = - ENOMEM ;
327+ goto exit ;
328+ }
329+
323330 nonseekable_open (inode , file );
324331 subminor = iminor (inode );
325332
@@ -364,8 +371,8 @@ static int tower_open (struct inode *inode, struct file *file)
364371 USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE ,
365372 0 ,
366373 0 ,
367- & reset_reply ,
368- sizeof (reset_reply ),
374+ reset_reply ,
375+ sizeof (* reset_reply ),
369376 1000 );
370377 if (result < 0 ) {
371378 dev_err (& dev -> udev -> dev ,
@@ -406,6 +413,7 @@ static int tower_open (struct inode *inode, struct file *file)
406413 mutex_unlock (& dev -> lock );
407414
408415exit :
416+ kfree (reset_reply );
409417 return retval ;
410418}
411419
@@ -806,7 +814,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
806814 struct device * idev = & interface -> dev ;
807815 struct usb_device * udev = interface_to_usbdev (interface );
808816 struct lego_usb_tower * dev = NULL ;
809- struct tower_get_version_reply get_version_reply ;
817+ struct tower_get_version_reply * get_version_reply = NULL ;
810818 int retval = - ENOMEM ;
811819 int result ;
812820
@@ -871,25 +879,33 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
871879 dev -> interrupt_in_interval = interrupt_in_interval ? interrupt_in_interval : dev -> interrupt_in_endpoint -> bInterval ;
872880 dev -> interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev -> interrupt_out_endpoint -> bInterval ;
873881
882+ get_version_reply = kmalloc (sizeof (* get_version_reply ), GFP_KERNEL );
883+
884+ if (!get_version_reply ) {
885+ retval = - ENOMEM ;
886+ goto error ;
887+ }
888+
874889 /* get the firmware version and log it */
875890 result = usb_control_msg (udev ,
876891 usb_rcvctrlpipe (udev , 0 ),
877892 LEGO_USB_TOWER_REQUEST_GET_VERSION ,
878893 USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE ,
879894 0 ,
880895 0 ,
881- & get_version_reply ,
882- sizeof (get_version_reply ),
896+ get_version_reply ,
897+ sizeof (* get_version_reply ),
883898 1000 );
884899 if (result < 0 ) {
885900 dev_err (idev , "LEGO USB Tower get version control request failed\n" );
886901 retval = result ;
887902 goto error ;
888903 }
889- dev_info (& interface -> dev , "LEGO USB Tower firmware version is %d.%d "
890- "build %d\n" , get_version_reply .major ,
891- get_version_reply .minor ,
892- le16_to_cpu (get_version_reply .build_no ));
904+ dev_info (& interface -> dev ,
905+ "LEGO USB Tower firmware version is %d.%d build %d\n" ,
906+ get_version_reply -> major ,
907+ get_version_reply -> minor ,
908+ le16_to_cpu (get_version_reply -> build_no ));
893909
894910 /* we can register the device now, as it is ready */
895911 usb_set_intfdata (interface , dev );
@@ -913,6 +929,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
913929 return retval ;
914930
915931error :
932+ kfree (get_version_reply );
916933 tower_delete (dev );
917934 return retval ;
918935}
0 commit comments