Skip to contentSkip to conversation

usbip: Remove unnecessary null check

PATCH In review Suwan Kim 2 participants 2 messages Mar 5, 2019 – Mar 6, 2019

Subsystems (2)
lore
Share & tools
lore

Suwan Kim

author
#0 lore raw

PATCH 1/1 usbip: Remove unnecessary null check

"vdev" points to vhci_hcd->vdev[] array and vhci_hcd->vdev[] array is not a pointer array but a structure array and it is already used in vhci_urb_enqueue() and then passed to vhci_tx_urb() as an argument. vhci_tx_urb() is not called except vhci_urb_enqueue(). So, "vdev" can not be null pointer. This null check statement is meaningless.

---
 drivers/usb/usbip/vhci_hcd.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/usbip/vhci_hcd.c +1 -7
index f46ee1fefe02..667d9c0ec905 100644
@@ -654,15 +654,9 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 static void vhci_tx_urb(struct urb *urb, struct vhci_device *vdev)
 {
 	struct vhci_priv *priv;
-	struct vhci_hcd *vhci_hcd;
+	struct vhci_hcd *vhci_hcd = vdev_to_vhci_hcd(vdev);
 	unsigned long flags;
 
-	if (!vdev) {
-		pr_err("could not get virtual device");
-		return;
-	}
-	vhci_hcd = vdev_to_vhci_hcd(vdev);
-
 	priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
 	if (!priv) {
 		usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Suwan,

Quoted 23 lines · Suwan Kim

"vdev" points to vhci_hcd->vdev[] array and vhci_hcd->vdev[] array is not a pointer array but a structure array and it is already used in vhci_urb_enqueue() and then passed to vhci_tx_urb() as an argument. vhci_tx_urb() is not called except vhci_urb_enqueue(). So, "vdev" can not be null pointer. This null check statement is meaningless.

---
  drivers/usb/usbip/vhci_hcd.c | 8 +-------
  1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/usbip/vhci_hcd.c +1 -1
index f46ee1fefe02..667d9c0ec905 100644
@@ -654,15 +654,9 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  static void vhci_tx_urb(struct urb *urb, struct vhci_device *vdev)
  {
  	struct vhci_priv *priv;
-	struct vhci_hcd *vhci_hcd;
+	struct vhci_hcd *vhci_hcd = vdev_to_vhci_hcd(vdev);
  	unsigned long flags;

drivers/usb/usbip/vhci_hcd.c static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, · line 662

Quoted 10 lines
drivers/usb/usbip/vhci_hcd.c +0 -6
 
-	if (!vdev) {
-		pr_err("could not get virtual device");
-		return;
-	}
-	vhci_hcd = vdev_to_vhci_hcd(vdev);
-
  	priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
  	if (!priv) {
  		usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);

Thanks for the patch. Looks good to me.

thanks,
-- Shuah