You need to sign in or sign up before continuing.
提交 fdd1432b 编写于 作者: P Pavel Skripkin 提交者: Yang Yingliang

net: caif: fix memory leak in cfusbl_device_notify

commit 7f5d8666 upstream.

In case of caif_enroll_dev() fail, allocated
link_support won't be assigned to the corresponding
structure. So simply free allocated pointer in case
of error.

Fixes: 7ad65bf6 ("caif: Add support for CAIF over CDC NCM USB interface")
Cc: stable@vger.kernel.org
Signed-off-by: NPavel Skripkin <paskripkin@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 dc807fcc
...@@ -116,6 +116,11 @@ static struct cflayer *cfusbl_create(int phyid, u8 ethaddr[ETH_ALEN], ...@@ -116,6 +116,11 @@ static struct cflayer *cfusbl_create(int phyid, u8 ethaddr[ETH_ALEN],
return (struct cflayer *) this; return (struct cflayer *) this;
} }
static void cfusbl_release(struct cflayer *layer)
{
kfree(layer);
}
static struct packet_type caif_usb_type __read_mostly = { static struct packet_type caif_usb_type __read_mostly = {
.type = cpu_to_be16(ETH_P_802_EX1), .type = cpu_to_be16(ETH_P_802_EX1),
}; };
...@@ -128,6 +133,7 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, ...@@ -128,6 +133,7 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
struct cflayer *layer, *link_support; struct cflayer *layer, *link_support;
struct usbnet *usbnet; struct usbnet *usbnet;
struct usb_device *usbdev; struct usb_device *usbdev;
int res;
/* Check whether we have a NCM device, and find its VID/PID. */ /* Check whether we have a NCM device, and find its VID/PID. */
if (!(dev->dev.parent && dev->dev.parent->driver && if (!(dev->dev.parent && dev->dev.parent->driver &&
...@@ -170,8 +176,11 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, ...@@ -170,8 +176,11 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
if (dev->num_tx_queues > 1) if (dev->num_tx_queues > 1)
pr_warn("USB device uses more than one tx queue\n"); pr_warn("USB device uses more than one tx queue\n");
caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, res = caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN,
&layer, &caif_usb_type.func); &layer, &caif_usb_type.func);
if (res)
goto err;
if (!pack_added) if (!pack_added)
dev_add_pack(&caif_usb_type); dev_add_pack(&caif_usb_type);
pack_added = true; pack_added = true;
...@@ -179,6 +188,9 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what, ...@@ -179,6 +188,9 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
strlcpy(layer->name, dev->name, sizeof(layer->name)); strlcpy(layer->name, dev->name, sizeof(layer->name));
return 0; return 0;
err:
cfusbl_release(link_support);
return res;
} }
static struct notifier_block caif_device_notifier = { static struct notifier_block caif_device_notifier = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册