* [PATCH 0/4] staging: most: usb: cleanup code
@ 2020-05-05 10:00 Christian Gromm
2020-05-05 10:00 ` [PATCH 1/4] staging: most: usb: remove overcautious parameter checking Christian Gromm
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Christian Gromm @ 2020-05-05 10:00 UTC (permalink / raw)
To: gregkh; +Cc: Christian Gromm, driverdev-devel
This patch set consolidates the source code appearance by rearranging or
removing unnecessary code and makes use of error codes that better signal
the exception.
Christian Gromm (4):
staging: most: usb: remove overcautious parameter checking
staging: most: usb: use EINVAL error code
staging: most: usb: drop unlikely macros
staging: most: usb: consolidate code
drivers/staging/most/usb/usb.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)
--
2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] staging: most: usb: remove overcautious parameter checking
2020-05-05 10:00 [PATCH 0/4] staging: most: usb: cleanup code Christian Gromm
@ 2020-05-05 10:00 ` Christian Gromm
2020-05-05 10:00 ` [PATCH 2/4] staging: most: usb: use EINVAL error code Christian Gromm
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christian Gromm @ 2020-05-05 10:00 UTC (permalink / raw)
To: gregkh; +Cc: Christian Gromm, driverdev-devel
The interface pointer passed to a core API function cannot be NULL. This
patch removes unnessecary the sanity check of the pointer.
Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/staging/most/usb/usb.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index e8c5a8c..9527e31 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -233,10 +233,6 @@ static int hdm_poison_channel(struct most_interface *iface, int channel)
unsigned long flags;
spinlock_t *lock; /* temp. lock */
- if (unlikely(!iface)) {
- dev_warn(&mdev->usb_device->dev, "Poison: Bad interface.\n");
- return -EIO;
- }
if (unlikely(channel < 0 || channel >= iface->num_channels)) {
dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n");
return -ECHRNG;
@@ -559,7 +555,7 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
unsigned long length;
void *virt_address;
- if (unlikely(!iface || !mbo))
+ if (unlikely(!mbo))
return -EIO;
if (unlikely(iface->num_channels <= channel || channel < 0))
return -ECHRNG;
@@ -674,8 +670,8 @@ static int hdm_configure_channel(struct most_interface *iface, int channel,
mdev->clear_work[channel].mdev = mdev;
INIT_WORK(&mdev->clear_work[channel].ws, wq_clear_halt);
- if (unlikely(!iface || !conf)) {
- dev_err(dev, "Bad interface or config pointer.\n");
+ if (unlikely(!conf)) {
+ dev_err(dev, "Bad config pointer.\n");
return -EINVAL;
}
if (unlikely(channel < 0 || channel >= iface->num_channels)) {
@@ -747,7 +743,6 @@ static void hdm_request_netinfo(struct most_interface *iface, int channel,
{
struct most_dev *mdev;
- BUG_ON(!iface);
mdev = to_mdev(iface);
mdev->on_netinfo = on_netinfo;
if (!on_netinfo)
--
2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] staging: most: usb: use EINVAL error code
2020-05-05 10:00 [PATCH 0/4] staging: most: usb: cleanup code Christian Gromm
2020-05-05 10:00 ` [PATCH 1/4] staging: most: usb: remove overcautious parameter checking Christian Gromm
@ 2020-05-05 10:00 ` Christian Gromm
2020-05-05 10:00 ` [PATCH 3/4] staging: most: usb: drop unlikely macros Christian Gromm
2020-05-05 10:00 ` [PATCH 4/4] staging: most: usb: consolidate code Christian Gromm
3 siblings, 0 replies; 5+ messages in thread
From: Christian Gromm @ 2020-05-05 10:00 UTC (permalink / raw)
To: gregkh; +Cc: Christian Gromm, driverdev-devel
This patch replaces the error code EIO with EINVAL, when there is no IO
happening.
Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
drivers/staging/most/usb/usb.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 9527e31..1087ad9 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -274,13 +274,13 @@ static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
unsigned int j, num_frames;
if (!frame_size)
- return -EIO;
+ return -EINVAL;
num_frames = mbo->buffer_length / frame_size;
if (num_frames < 1) {
dev_err(&mdev->usb_device->dev,
"Missed minimal transfer unit.\n");
- return -EIO;
+ return -EINVAL;
}
for (j = num_frames - 1; j > 0; j--)
@@ -308,7 +308,7 @@ static int hdm_remove_padding(struct most_dev *mdev, int channel,
unsigned int j, num_frames;
if (!frame_size)
- return -EIO;
+ return -EINVAL;
num_frames = mbo->processed_length / USB_MTU;
for (j = 1; j < num_frames; j++)
@@ -556,7 +556,7 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
void *virt_address;
if (unlikely(!mbo))
- return -EIO;
+ return -EINVAL;
if (unlikely(iface->num_channels <= channel || channel < 0))
return -ECHRNG;
@@ -577,7 +577,7 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] &&
hdm_add_padding(mdev, channel, mbo)) {
- retval = -EIO;
+ retval = -EINVAL;
goto err_free_urb;
}
--
2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] staging: most: usb: drop unlikely macros
2020-05-05 10:00 [PATCH 0/4] staging: most: usb: cleanup code Christian Gromm
2020-05-05 10:00 ` [PATCH 1/4] staging: most: usb: remove overcautious parameter checking Christian Gromm
2020-05-05 10:00 ` [PATCH 2/4] staging: most: usb: use EINVAL error code Christian Gromm
@ 2020-05-05 10:00 ` Christian Gromm
2020-05-05 10:00 ` [PATCH 4/4] staging: most: usb: consolidate code Christian Gromm
3 siblings, 0 replies; 5+ messages in thread
From: Christian Gromm @ 2020-05-05 10:00 UTC (permalink / raw)
To: gregkh; +Cc: Christian Gromm, driverdev-devel
This patch removes the unlikely macros in the error patch of argument
checking, as it has no measurable performance adavantage.
Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/staging/most/usb/usb.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 1087ad9..62d773c 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -233,7 +233,7 @@ static int hdm_poison_channel(struct most_interface *iface, int channel)
unsigned long flags;
spinlock_t *lock; /* temp. lock */
- if (unlikely(channel < 0 || channel >= iface->num_channels)) {
+ if (channel < 0 || channel >= iface->num_channels) {
dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n");
return -ECHRNG;
}
@@ -555,9 +555,9 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
unsigned long length;
void *virt_address;
- if (unlikely(!mbo))
+ if (!mbo)
return -EINVAL;
- if (unlikely(iface->num_channels <= channel || channel < 0))
+ if (iface->num_channels <= channel || channel < 0)
return -ECHRNG;
mdev = to_mdev(iface);
@@ -670,11 +670,11 @@ static int hdm_configure_channel(struct most_interface *iface, int channel,
mdev->clear_work[channel].mdev = mdev;
INIT_WORK(&mdev->clear_work[channel].ws, wq_clear_halt);
- if (unlikely(!conf)) {
+ if (!conf) {
dev_err(dev, "Bad config pointer.\n");
return -EINVAL;
}
- if (unlikely(channel < 0 || channel >= iface->num_channels)) {
+ if (channel < 0 || channel >= iface->num_channels) {
dev_err(dev, "Channel ID out of range.\n");
return -EINVAL;
}
--
2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] staging: most: usb: consolidate code
2020-05-05 10:00 [PATCH 0/4] staging: most: usb: cleanup code Christian Gromm
` (2 preceding siblings ...)
2020-05-05 10:00 ` [PATCH 3/4] staging: most: usb: drop unlikely macros Christian Gromm
@ 2020-05-05 10:00 ` Christian Gromm
3 siblings, 0 replies; 5+ messages in thread
From: Christian Gromm @ 2020-05-05 10:00 UTC (permalink / raw)
To: gregkh; +Cc: Christian Gromm, driverdev-devel
This patch applies the same look and feel when assigning local variables.
Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
drivers/staging/most/usb/usb.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index 62d773c..b31a49c 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -548,7 +548,7 @@ static void hdm_read_completion(struct urb *urb)
static int hdm_enqueue(struct most_interface *iface, int channel,
struct mbo *mbo)
{
- struct most_dev *mdev;
+ struct most_dev *mdev = to_mdev(iface);
struct most_channel_config *conf;
int retval = 0;
struct urb *urb;
@@ -560,7 +560,6 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
if (iface->num_channels <= channel || channel < 0)
return -ECHRNG;
- mdev = to_mdev(iface);
conf = &mdev->conf[channel];
mutex_lock(&mdev->io_mutex);
@@ -741,9 +740,8 @@ static void hdm_request_netinfo(struct most_interface *iface, int channel,
unsigned char,
unsigned char *))
{
- struct most_dev *mdev;
+ struct most_dev *mdev = to_mdev(iface);
- mdev = to_mdev(iface);
mdev->on_netinfo = on_netinfo;
if (!on_netinfo)
return;
--
2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-05-05 10:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 10:00 [PATCH 0/4] staging: most: usb: cleanup code Christian Gromm
2020-05-05 10:00 ` [PATCH 1/4] staging: most: usb: remove overcautious parameter checking Christian Gromm
2020-05-05 10:00 ` [PATCH 2/4] staging: most: usb: use EINVAL error code Christian Gromm
2020-05-05 10:00 ` [PATCH 3/4] staging: most: usb: drop unlikely macros Christian Gromm
2020-05-05 10:00 ` [PATCH 4/4] staging: most: usb: consolidate code 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).