All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Gromm <christian.gromm@microchip.com>
To: <gregkh@linuxfoundation.org>
Cc: <driverdev-devel@linuxdriverproject.org>,
	<linux-usb@vger.kernel.org>,
	Christian Gromm <christian.gromm@microchip.com>
Subject: [PATCH v2 4/8] drivers: most: usb: check number of reported endpoints
Date: Thu, 14 May 2020 11:52:52 +0200	[thread overview]
Message-ID: <1589449976-11378-5-git-send-email-christian.gromm@microchip.com> (raw)
In-Reply-To: <1589449976-11378-1-git-send-email-christian.gromm@microchip.com>

This patch checks the number of endpoints reported by the USB
interface descriptor and throws an error if the number exceeds
MAX_NUM_ENDPOINTS.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2:

 drivers/most/most_usb.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index 49d0b40..1655fcd 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -1044,13 +1044,17 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 	unsigned int num_endpoints;
 	struct most_channel_capability *tmp_cap;
 	struct usb_endpoint_descriptor *ep_desc;
-	int ret = 0;
+	int ret;
 
 	if (!mdev)
-		goto err_out_of_memory;
+		return -ENOMEM;
 
 	usb_set_intfdata(interface, mdev);
 	num_endpoints = usb_iface_desc->desc.bNumEndpoints;
+	if (num_endpoints > MAX_NUM_ENDPOINTS) {
+		kfree(mdev);
+		return -EINVAL;
+	}
 	mutex_init(&mdev->io_mutex);
 	INIT_WORK(&mdev->poll_work_obj, wq_netinfo);
 	timer_setup(&mdev->link_stat_timer, link_stat_timer_handler, 0);
@@ -1179,11 +1183,6 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 	kfree(mdev->conf);
 err_free_mdev:
 	put_device(&mdev->dev);
-err_out_of_memory:
-	if (ret == 0 || ret == -ENOMEM) {
-		ret = -ENOMEM;
-		dev_err(dev, "out of memory\n");
-	}
 	return ret;
 }
 
-- 
2.7.4


WARNING: multiple messages have this Message-ID (diff)
From: Christian Gromm <christian.gromm@microchip.com>
To: <gregkh@linuxfoundation.org>
Cc: Christian Gromm <christian.gromm@microchip.com>,
	driverdev-devel@linuxdriverproject.org,
	linux-usb@vger.kernel.org
Subject: [PATCH v2 4/8] drivers: most: usb: check number of reported endpoints
Date: Thu, 14 May 2020 11:52:52 +0200	[thread overview]
Message-ID: <1589449976-11378-5-git-send-email-christian.gromm@microchip.com> (raw)
In-Reply-To: <1589449976-11378-1-git-send-email-christian.gromm@microchip.com>

This patch checks the number of endpoints reported by the USB
interface descriptor and throws an error if the number exceeds
MAX_NUM_ENDPOINTS.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2:

 drivers/most/most_usb.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index 49d0b40..1655fcd 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -1044,13 +1044,17 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 	unsigned int num_endpoints;
 	struct most_channel_capability *tmp_cap;
 	struct usb_endpoint_descriptor *ep_desc;
-	int ret = 0;
+	int ret;
 
 	if (!mdev)
-		goto err_out_of_memory;
+		return -ENOMEM;
 
 	usb_set_intfdata(interface, mdev);
 	num_endpoints = usb_iface_desc->desc.bNumEndpoints;
+	if (num_endpoints > MAX_NUM_ENDPOINTS) {
+		kfree(mdev);
+		return -EINVAL;
+	}
 	mutex_init(&mdev->io_mutex);
 	INIT_WORK(&mdev->poll_work_obj, wq_netinfo);
 	timer_setup(&mdev->link_stat_timer, link_stat_timer_handler, 0);
@@ -1179,11 +1183,6 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 	kfree(mdev->conf);
 err_free_mdev:
 	put_device(&mdev->dev);
-err_out_of_memory:
-	if (ret == 0 || ret == -ENOMEM) {
-		ret = -ENOMEM;
-		dev_err(dev, "out of memory\n");
-	}
 	return ret;
 }
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2020-05-14  9:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14  9:52 [PATCH v2 0/8] staging: most: move USB adapter driver to stable branch Christian Gromm
2020-05-14  9:52 ` Christian Gromm
2020-05-14  9:52 ` [PATCH v2 1/8] drivers: most: add usb adapter driver Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-14 10:25   ` Greg KH
2020-05-14 10:25     ` Greg KH
2020-05-20 13:17   ` Dan Carpenter
2020-05-20 13:17     ` Dan Carpenter
2020-05-20 13:54     ` Christian.Gromm
2020-05-20 13:54       ` Christian.Gromm
2020-05-14  9:52 ` [PATCH v2 2/8] drivers: most: usb: use dev_*() functions to print messages Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-19 13:42   ` Dan Carpenter
2020-05-19 13:42     ` Dan Carpenter
2020-05-14  9:52 ` [PATCH v2 3/8] drivers: most: usb: remove reference to USB error codes Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-14  9:52 ` Christian Gromm [this message]
2020-05-14  9:52   ` [PATCH v2 4/8] drivers: most: usb: check number of reported endpoints Christian Gromm
2020-05-14 20:53   ` kbuild test robot
2020-05-14 20:53     ` kbuild test robot
2020-05-14 20:53     ` kbuild test robot
2020-05-14  9:52 ` [PATCH v2 5/8] drivers: most: usb: use dev_dbg function Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-19 13:43   ` Dan Carpenter
2020-05-19 13:43     ` Dan Carpenter
2020-05-14  9:52 ` [PATCH v2 6/8] drivers: most: fix typo in Kconfig Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-14  9:52 ` [PATCH v2 7/8] drivers: most: usb: use macro ATTRIBUTE_GROUPS Christian Gromm
2020-05-14  9:52   ` Christian Gromm
2020-05-14  9:52 ` [PATCH v2 8/8] Documentation: ABI: correct sysfs attribute description of MOST driver Christian Gromm
2020-05-14  9:52   ` Christian Gromm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1589449976-11378-5-git-send-email-christian.gromm@microchip.com \
    --to=christian.gromm@microchip.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.