usb: gadget: f_mtp: simplify ptp NULL pointer check
authorAmit Pundir <amit.pundir@linaro.org>
Tue, 11 Aug 2015 07:04:45 +0000 (12:34 +0530)
committerAmit Pundir <amit.pundir@linaro.org>
Thu, 1 Dec 2016 09:48:16 +0000 (15:18 +0530)
Simplify MTP/PTP dev NULL pointer check introduced in
Change-Id: Ic44a699d96df2e13467fc081bff88b97dcc5afb2
and restrict it to MTP/PTP function level only.

Return ERR_PTR() instead of NULL from mtp_ptp function
to skip doing NULL pointer checks all the way up to
configfs.c

Fixes: Change-Id: Ic44a699d96df2e13467fc081bff88b97dcc5afb2
       ("usb: gadget: fix NULL ptr derefer while symlinking PTP func")
Change-Id: Iab7c55089c115550c3506f6cca960a07ae52713d
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
drivers/usb/gadget/configfs.c
drivers/usb/gadget/function/f_mtp.c
drivers/usb/gadget/functions.c

index 8df96cb3bb582d5d6d8974ba67aea1f5f933569e..54849fe9cb01ed8c6b64ebfc3c3e08edd243af89 100644 (file)
@@ -425,11 +425,6 @@ static int config_usb_cfg_link(
        }
 
        f = usb_get_function(fi);
-       if (f == NULL) {
-               /* Are we trying to symlink PTP without MTP function? */
-               ret = -EINVAL; /* Invalid Configuration */
-               goto out;
-       }
        if (IS_ERR(f)) {
                ret = PTR_ERR(f);
                goto out;
index 74195be9b054ae4f547fd526615a9ba8d917677c..b9e3e97c57c429defeaa374ec88d2ec66d4131c8 100644 (file)
@@ -1498,7 +1498,7 @@ struct usb_function *function_alloc_mtp_ptp(struct usb_function_instance *fi,
                pr_err("\t2: Create MTP function\n");
                pr_err("\t3: Create and symlink PTP function"
                                " with a gadget configuration\n");
-               return NULL;
+               return ERR_PTR(-EINVAL); /* Invalid Configuration */
        }
 
        dev = fi_mtp->dev;
index 389c1f3d0feedd5664b3f5c733b3dce9c89627bc..b13f839e73682d5c26de4b1a984510eb9e92d6cb 100644 (file)
@@ -58,7 +58,7 @@ struct usb_function *usb_get_function(struct usb_function_instance *fi)
        struct usb_function *f;
 
        f = fi->fd->alloc_func(fi);
-       if ((f == NULL) || IS_ERR(f))
+       if (IS_ERR(f))
                return f;
        f->fi = fi;
        return f;