linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] staging: most: usb: fix code review findings
@ 2020-05-27  9:06 Christian Gromm
  2020-05-27  9:06 ` [PATCH 01/10] staging: most: usb: change order of function parameters Christian Gromm
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This series fixes the comments received from the mailing list.

Christian Gromm (10):
  staging: most: usb: change order of function parameters
  staging: most: usb: don't use expressions that might fail in a
    declaration
  staging: most: usb: change return value of function drci_rd_reg
  staging: most: usb: return 0 instead of variable
  staging: most: usb: move allocation of URB out of critical section
  staging: most: usb: don't use error path to exit function on success
  staging: most: usb: replace code to calculate array index
  staging: most: usb: use correct error codes
  staging: most: usb: add missing put_device calls
  staging: most: usb: use function sysfs_streq

 drivers/staging/most/usb/usb.c | 83 ++++++++++++++++++++++++------------------
 1 file changed, 47 insertions(+), 36 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] staging: most: usb: change order of function parameters
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 02/10] staging: most: usb: don't use expressions that might fail in a declaration Christian Gromm
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch swaps the arguments of function get_stream_frame_size to
have the struct device as first parameter.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 56b75e4..0e1264d 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -183,10 +183,11 @@ static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep)
 
 /**
  * get_stream_frame_size - calculate frame size of current configuration
+ * @dev: device structure
  * @cfg: channel configuration
  */
-static unsigned int get_stream_frame_size(struct most_channel_config *cfg,
-					  struct device *dev)
+static unsigned int get_stream_frame_size(struct device *dev,
+					  struct most_channel_config *cfg)
 {
 	unsigned int frame_size = 0;
 	unsigned int sub_size = cfg->subbuffer_size;
@@ -270,7 +271,7 @@ static int hdm_poison_channel(struct most_interface *iface, int channel)
 static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
 {
 	struct most_channel_config *conf = &mdev->conf[channel];
-	unsigned int frame_size = get_stream_frame_size(conf, &mdev->dev);
+	unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf);
 	unsigned int j, num_frames;
 
 	if (!frame_size)
@@ -304,7 +305,7 @@ static int hdm_remove_padding(struct most_dev *mdev, int channel,
 			      struct mbo *mbo)
 {
 	struct most_channel_config *const conf = &mdev->conf[channel];
-	unsigned int frame_size = get_stream_frame_size(conf, &mdev->dev);
+	unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf);
 	unsigned int j, num_frames;
 
 	if (!frame_size)
@@ -600,7 +601,7 @@ static int hdm_configure_channel(struct most_interface *iface, int channel,
 
 	mdev->padding_active[channel] = true;
 
-	frame_size = get_stream_frame_size(conf, &mdev->dev);
+	frame_size = get_stream_frame_size(&mdev->dev, conf);
 	if (frame_size == 0 || frame_size > USB_MTU) {
 		dev_warn(dev, "Misconfig: frame size wrong\n");
 		return -EINVAL;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] staging: most: usb: don't use expressions that might fail in a declaration
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
  2020-05-27  9:06 ` [PATCH 01/10] staging: most: usb: change order of function parameters Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 03/10] staging: most: usb: change return value of function drci_rd_reg Christian Gromm
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch moves function calls that can fail out of the declararion block
of a function body. This is done to enhance readability.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 0e1264d..fd0d885 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -139,9 +139,10 @@ static void wq_netinfo(struct work_struct *wq_obj);
 static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
 {
 	int retval;
-	__le16 *dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL);
+	__le16 *dma_buf;
 	u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
 
+	dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL);
 	if (!dma_buf)
 		return -ENOMEM;
 
@@ -846,8 +847,9 @@ static ssize_t value_store(struct device *dev, struct device_attribute *attr,
 	const char *name = attr->attr.name;
 	struct most_dci_obj *dci_obj = to_dci_obj(dev);
 	struct usb_device *usb_dev = dci_obj->usb_device;
-	int err = kstrtou16(buf, 16, &val);
+	int err;
 
+	err = kstrtou16(buf, 16, &val);
 	if (err)
 		return err;
 
@@ -939,13 +941,14 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 	struct usb_host_interface *usb_iface_desc = interface->cur_altsetting;
 	struct usb_device *usb_dev = interface_to_usbdev(interface);
 	struct device *dev = &usb_dev->dev;
-	struct most_dev *mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+	struct most_dev *mdev;
 	unsigned int i;
 	unsigned int num_endpoints;
 	struct most_channel_capability *tmp_cap;
 	struct usb_endpoint_descriptor *ep_desc;
 	int ret = -ENOMEM;
 
+	mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
 	if (!mdev)
 		return -ENOMEM;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] staging: most: usb: change return value of function drci_rd_reg
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
  2020-05-27  9:06 ` [PATCH 01/10] staging: most: usb: change order of function parameters Christian Gromm
  2020-05-27  9:06 ` [PATCH 02/10] staging: most: usb: don't use expressions that might fail in a declaration Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 04/10] staging: most: usb: return 0 instead of variable Christian Gromm
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch makes function drci_rd_reg return 0 in case of success
and a negative number else. As no caller is evaluating the number
of bytes transferred by function usb_control_msg this information is
being omitted.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index fd0d885..64005b6 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -153,7 +153,9 @@ static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
 	*buf = le16_to_cpu(*dma_buf);
 	kfree(dma_buf);
 
-	return retval;
+	if (retval < 0)
+		return retval;
+	return 0;
 }
 
 /**
@@ -686,22 +688,22 @@ static void wq_netinfo(struct work_struct *wq_obj)
 	u16 hi, mi, lo, link;
 	u8 hw_addr[6];
 
-	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi) < 0) {
+	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi)) {
 		dev_err(dev, "Vendor request 'hw_addr_hi' failed\n");
 		return;
 	}
 
-	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi) < 0) {
+	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi)) {
 		dev_err(dev, "Vendor request 'hw_addr_mid' failed\n");
 		return;
 	}
 
-	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo) < 0) {
+	if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo)) {
 		dev_err(dev, "Vendor request 'hw_addr_low' failed\n");
 		return;
 	}
 
-	if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link) < 0) {
+	if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link)) {
 		dev_err(dev, "Vendor request 'link status' failed\n");
 		return;
 	}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] staging: most: usb: return 0 instead of variable
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (2 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 03/10] staging: most: usb: change return value of function drci_rd_reg Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 05/10] staging: most: usb: move allocation of URB out of critical section Christian Gromm
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch returns 0 instead of variable in case of invalid parameter
has been passed to function to increase readability.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 64005b6..a605e0f 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -192,12 +192,12 @@ static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep)
 static unsigned int get_stream_frame_size(struct device *dev,
 					  struct most_channel_config *cfg)
 {
-	unsigned int frame_size = 0;
+	unsigned int frame_size;
 	unsigned int sub_size = cfg->subbuffer_size;
 
 	if (!sub_size) {
 		dev_warn(dev, "Misconfig: Subbuffer size zero.\n");
-		return frame_size;
+		return 0;
 	}
 	switch (cfg->data_type) {
 	case MOST_CH_ISOC:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] staging: most: usb: move allocation of URB out of critical section
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (3 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 04/10] staging: most: usb: return 0 instead of variable Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 06/10] staging: most: usb: don't use error path to exit function on success Christian Gromm
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch puts the call to usb_alloc_urb() before the critical
section starts that is protected with the io_mutex lock. This is
to make the section as short as possible and to use the regular
GFP_KERNEL flag.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index a605e0f..534825f 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -467,18 +467,16 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
 	if (iface->num_channels <= channel || channel < 0)
 		return -ECHRNG;
 
+	urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_KERNEL);
+	if (!urb)
+		return -ENOMEM;
+
 	conf = &mdev->conf[channel];
 
 	mutex_lock(&mdev->io_mutex);
 	if (!mdev->usb_device) {
 		retval = -ENODEV;
-		goto unlock_io_mutex;
-	}
-
-	urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC);
-	if (!urb) {
-		retval = -ENOMEM;
-		goto unlock_io_mutex;
+		goto err_free_urb;
 	}
 
 	if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] &&
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] staging: most: usb: don't use error path to exit function on success
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (4 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 05/10] staging: most: usb: move allocation of URB out of critical section Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 07/10] staging: most: usb: replace code to calculate array index Christian Gromm
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch makes it transparent whether the function is exiting
with an error or successful.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 534825f..03318de 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -519,13 +519,13 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
 			"URB submit failed with error %d.\n", retval);
 		goto err_unanchor_urb;
 	}
-	goto unlock_io_mutex;
+	mutex_unlock(&mdev->io_mutex);
+	return 0;
 
 err_unanchor_urb:
 	usb_unanchor_urb(urb);
 err_free_urb:
 	usb_free_urb(urb);
-unlock_io_mutex:
 	mutex_unlock(&mdev->io_mutex);
 	return retval;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] staging: most: usb: replace code to calculate array index
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (5 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 06/10] staging: most: usb: don't use error path to exit function on success Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 08/10] staging: most: usb: use correct error codes Christian Gromm
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch removes the expression that makes use of a priori knowledge
about channel numbers to calculate an array index.
The expression 'peer = 1 - channel' utilizes the fact that an USB interface
that operates on the asynchronous data of the Network only has two
endpoints. Hence, channel being 0 or 1. The replacement is more simple and
less confusing when reading the code.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 03318de..468aabf 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -729,6 +729,8 @@ static void wq_clear_halt(struct work_struct *wq_obj)
 	struct most_dev *mdev = clear_work->mdev;
 	unsigned int channel = clear_work->channel;
 	int pipe = clear_work->pipe;
+	int snd_pipe;
+	int peer;
 
 	mutex_lock(&mdev->io_mutex);
 	most_stop_enqueue(&mdev->iface, channel);
@@ -746,9 +748,12 @@ static void wq_clear_halt(struct work_struct *wq_obj)
 	 */
 	if (mdev->conf[channel].data_type == MOST_CH_ASYNC &&
 	    mdev->conf[channel].direction == MOST_CH_RX) {
-		int peer = 1 - channel;
-		int snd_pipe = usb_sndbulkpipe(mdev->usb_device,
-					       mdev->ep_address[peer]);
+		if (channel == 0)
+			peer = 1;
+		else
+			peer = 0;
+		snd_pipe = usb_sndbulkpipe(mdev->usb_device,
+					   mdev->ep_address[peer]);
 		usb_clear_halt(mdev->usb_device, snd_pipe);
 	}
 	mdev->is_channel_healthy[channel] = true;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] staging: most: usb: use correct error codes
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (6 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 07/10] staging: most: usb: replace code to calculate array index Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 09/10] staging: most: usb: add missing put_device calls Christian Gromm
  2020-05-27  9:06 ` [PATCH 10/10] staging: most: usb: use function sysfs_streq Christian Gromm
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch uses the -EINVAL return code where -EFAULT is wrongly being
used.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 468aabf..3575a40 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -813,7 +813,7 @@ static int get_stat_reg_addr(const struct regs *regs, int size,
 			return 0;
 		}
 	}
-	return -EFAULT;
+	return -EINVAL;
 }
 
 #define get_static_reg_addr(regs, name, reg_addr) \
@@ -835,7 +835,7 @@ static ssize_t value_show(struct device *dev, struct device_attribute *attr,
 		reg_addr = dci_obj->reg_addr;
 	else if (get_static_reg_addr(ro_regs, name, &reg_addr) &&
 		 get_static_reg_addr(rw_regs, name, &reg_addr))
-		return -EFAULT;
+		return -EINVAL;
 
 	err = drci_rd_reg(dci_obj->usb_device, reg_addr, &val);
 	if (err < 0)
@@ -870,7 +870,7 @@ static ssize_t value_store(struct device *dev, struct device_attribute *attr,
 	else if (!get_static_reg_addr(rw_regs, name, &reg_addr))
 		err = drci_wr_reg(usb_dev, reg_addr, val);
 	else
-		return -EFAULT;
+		return -EINVAL;
 
 	if (err < 0)
 		return err;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] staging: most: usb: add missing put_device calls
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (7 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 08/10] staging: most: usb: use correct error codes Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  2020-05-27  9:06 ` [PATCH 10/10] staging: most: usb: use function sysfs_streq Christian Gromm
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch adds the missing put_device() function calls to
properly free allocated resources and maintain reference counts.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 3575a40..1c4bdb8 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -919,6 +919,7 @@ static void release_dci(struct device *dev)
 {
 	struct most_dci_obj *dci = to_dci_obj(dev);
 
+	put_device(dev->parent);
 	kfree(dci);
 }
 
@@ -1123,6 +1124,7 @@ static void hdm_disconnect(struct usb_interface *interface)
 	kfree(mdev->cap);
 	kfree(mdev->conf);
 	kfree(mdev->ep_address);
+	put_device(&mdev->dci->dev);
 	put_device(&mdev->dev);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] staging: most: usb: use function sysfs_streq
  2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
                   ` (8 preceding siblings ...)
  2020-05-27  9:06 ` [PATCH 09/10] staging: most: usb: add missing put_device calls Christian Gromm
@ 2020-05-27  9:06 ` Christian Gromm
  9 siblings, 0 replies; 11+ messages in thread
From: Christian Gromm @ 2020-05-27  9:06 UTC (permalink / raw)
  To: gregkh; +Cc: driverdev-devel, linux-usb, Christian Gromm

This patch replaces function strcmp() with sysfs_streq() to compare
strings provided via sysfs.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/staging/most/usb/usb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 1c4bdb8..df5876c 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -808,7 +808,7 @@ static int get_stat_reg_addr(const struct regs *regs, int size,
 	int i;
 
 	for (i = 0; i < size; i++) {
-		if (!strcmp(name, regs[i].name)) {
+		if (sysfs_streq(name, regs[i].name)) {
 			*reg_addr = regs[i].reg;
 			return 0;
 		}
@@ -828,10 +828,10 @@ static ssize_t value_show(struct device *dev, struct device_attribute *attr,
 	u16 reg_addr;
 	int err;
 
-	if (!strcmp(name, "arb_address"))
+	if (sysfs_streq(name, "arb_address"))
 		return snprintf(buf, PAGE_SIZE, "%04x\n", dci_obj->reg_addr);
 
-	if (!strcmp(name, "arb_value"))
+	if (sysfs_streq(name, "arb_value"))
 		reg_addr = dci_obj->reg_addr;
 	else if (get_static_reg_addr(ro_regs, name, &reg_addr) &&
 		 get_static_reg_addr(rw_regs, name, &reg_addr))
@@ -858,14 +858,14 @@ static ssize_t value_store(struct device *dev, struct device_attribute *attr,
 	if (err)
 		return err;
 
-	if (!strcmp(name, "arb_address")) {
+	if (sysfs_streq(name, "arb_address")) {
 		dci_obj->reg_addr = val;
 		return count;
 	}
 
-	if (!strcmp(name, "arb_value"))
+	if (sysfs_streq(name, "arb_value"))
 		err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val);
-	else if (!strcmp(name, "sync_ep"))
+	else if (sysfs_streq(name, "sync_ep"))
 		err = start_sync_ep(usb_dev, val);
 	else if (!get_static_reg_addr(rw_regs, name, &reg_addr))
 		err = drci_wr_reg(usb_dev, reg_addr, val);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-27  9:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27  9:06 [PATCH 00/10] staging: most: usb: fix code review findings Christian Gromm
2020-05-27  9:06 ` [PATCH 01/10] staging: most: usb: change order of function parameters Christian Gromm
2020-05-27  9:06 ` [PATCH 02/10] staging: most: usb: don't use expressions that might fail in a declaration Christian Gromm
2020-05-27  9:06 ` [PATCH 03/10] staging: most: usb: change return value of function drci_rd_reg Christian Gromm
2020-05-27  9:06 ` [PATCH 04/10] staging: most: usb: return 0 instead of variable Christian Gromm
2020-05-27  9:06 ` [PATCH 05/10] staging: most: usb: move allocation of URB out of critical section Christian Gromm
2020-05-27  9:06 ` [PATCH 06/10] staging: most: usb: don't use error path to exit function on success Christian Gromm
2020-05-27  9:06 ` [PATCH 07/10] staging: most: usb: replace code to calculate array index Christian Gromm
2020-05-27  9:06 ` [PATCH 08/10] staging: most: usb: use correct error codes Christian Gromm
2020-05-27  9:06 ` [PATCH 09/10] staging: most: usb: add missing put_device calls Christian Gromm
2020-05-27  9:06 ` [PATCH 10/10] staging: most: usb: use function sysfs_streq Christian Gromm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).