* [PATCH 1/3] [media] pvrusb2-ioread: Use common error handling code in pvr2_ioread_get_buffer()
2017-09-20 6:33 [PATCH 0/3] [media] pvrusb2-ioread: Fine-tuning for eight function implementations SF Markus Elfring
@ 2017-09-20 6:36 ` SF Markus Elfring
2017-09-20 6:37 ` [PATCH 2/3] [media] pvrusb2-ioread: Delete an unnecessary check before kfree() in two functions SF Markus Elfring
2017-09-20 6:38 ` [PATCH 3/3] [media] pvrusb2-ioread: Delete unnecessary braces in six functions SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-20 6:36 UTC (permalink / raw)
To: linux-media, Mauro Carvalho Chehab, Mike Isely; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 19 Sep 2017 21:50:05 +0200
Add a jump target so that a bit of exception handling can be better reused
at the end of this function.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
index 602097bdcf14..0218614ce988 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
@@ -266,8 +266,7 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)
pvr2_trace(PVR2_TRACE_DATA_FLOW,
"/*---TRACE_READ---*/ pvr2_ioread_read id=%p queue_error=%d",
cp,stat);
- pvr2_ioread_stop(cp);
- return 0;
+ goto stop_read;
}
cp->c_buf = NULL;
cp->c_data_ptr = NULL;
@@ -286,9 +285,8 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)
pvr2_trace(PVR2_TRACE_DATA_FLOW,
"/*---TRACE_READ---*/ pvr2_ioread_read id=%p buffer_error=%d",
cp,stat);
- pvr2_ioread_stop(cp);
// Give up.
- return 0;
+ goto stop_read;
}
// Start over...
continue;
@@ -298,6 +296,10 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)
pvr2_buffer_get_id(cp->c_buf)];
}
return !0;
+
+stop_read:
+ pvr2_ioread_stop(cp);
+ return 0;
}
static void pvr2_ioread_filter(struct pvr2_ioread *cp)
--
2.14.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] [media] pvrusb2-ioread: Delete an unnecessary check before kfree() in two functions
2017-09-20 6:33 [PATCH 0/3] [media] pvrusb2-ioread: Fine-tuning for eight function implementations SF Markus Elfring
2017-09-20 6:36 ` [PATCH 1/3] [media] pvrusb2-ioread: Use common error handling code in pvr2_ioread_get_buffer() SF Markus Elfring
@ 2017-09-20 6:37 ` SF Markus Elfring
2017-09-20 6:38 ` [PATCH 3/3] [media] pvrusb2-ioread: Delete unnecessary braces in six functions SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-20 6:37 UTC (permalink / raw)
To: linux-media, Mauro Carvalho Chehab, Mike Isely; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 19 Sep 2017 22:12:49 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: kfree(NULL) is safe and this check is probably not required
Thus fix the affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
index 0218614ce988..4349f9b5f838 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
@@ -98,10 +98,8 @@ void pvr2_ioread_destroy(struct pvr2_ioread *cp)
if (!cp) return;
pvr2_ioread_done(cp);
pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_destroy id=%p",cp);
- if (cp->sync_key_ptr) {
- kfree(cp->sync_key_ptr);
- cp->sync_key_ptr = NULL;
- }
+ kfree(cp->sync_key_ptr);
+ cp->sync_key_ptr = NULL;
kfree(cp);
}
@@ -117,10 +115,8 @@ void pvr2_ioread_set_sync_key(struct pvr2_ioread *cp,
(!memcmp(sync_key_ptr,cp->sync_key_ptr,sync_key_len)))) return;
if (sync_key_len != cp->sync_key_len) {
- if (cp->sync_key_ptr) {
- kfree(cp->sync_key_ptr);
- cp->sync_key_ptr = NULL;
- }
+ kfree(cp->sync_key_ptr);
+ cp->sync_key_ptr = NULL;
cp->sync_key_len = 0;
if (sync_key_len) {
cp->sync_key_ptr = kmalloc(sync_key_len,GFP_KERNEL);
--
2.14.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] [media] pvrusb2-ioread: Delete unnecessary braces in six functions
2017-09-20 6:33 [PATCH 0/3] [media] pvrusb2-ioread: Fine-tuning for eight function implementations SF Markus Elfring
2017-09-20 6:36 ` [PATCH 1/3] [media] pvrusb2-ioread: Use common error handling code in pvr2_ioread_get_buffer() SF Markus Elfring
2017-09-20 6:37 ` [PATCH 2/3] [media] pvrusb2-ioread: Delete an unnecessary check before kfree() in two functions SF Markus Elfring
@ 2017-09-20 6:38 ` SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-20 6:38 UTC (permalink / raw)
To: linux-media, Mauro Carvalho Chehab, Mike Isely; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 20 Sep 2017 08:15:51 +0200
Do not use curly brackets at some source code places
where a single statement should be sufficient.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 38 ++++++++++++------------------
1 file changed, 15 insertions(+), 23 deletions(-)
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
index 4349f9b5f838..9a0eb2875c9a 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
@@ -120,9 +120,8 @@ void pvr2_ioread_set_sync_key(struct pvr2_ioread *cp,
cp->sync_key_len = 0;
if (sync_key_len) {
cp->sync_key_ptr = kmalloc(sync_key_len,GFP_KERNEL);
- if (cp->sync_key_ptr) {
+ if (cp->sync_key_ptr)
cp->sync_key_len = sync_key_len;
- }
}
}
if (!cp->sync_key_len) return;
@@ -203,9 +202,9 @@ int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp)
cp);
pvr2_ioread_stop(cp);
pvr2_stream_kill(cp->stream);
- if (pvr2_stream_get_buffer_count(cp->stream)) {
+ if (pvr2_stream_get_buffer_count(cp->stream))
pvr2_stream_set_buffer_count(cp->stream,0);
- }
+
cp->stream = NULL;
}
if (sp) {
@@ -238,13 +237,10 @@ int pvr2_ioread_set_enabled(struct pvr2_ioread *cp,int fl)
if ((!fl) == (!(cp->enabled))) return ret;
mutex_lock(&cp->mutex);
- do {
- if (fl) {
- ret = pvr2_ioread_start(cp);
- } else {
- pvr2_ioread_stop(cp);
- }
- } while (0);
+ if (fl)
+ ret = pvr2_ioread_start(cp);
+ else
+ pvr2_ioread_stop(cp);
mutex_unlock(&cp->mutex);
return ret;
}
@@ -318,13 +314,12 @@ static void pvr2_ioread_filter(struct pvr2_ioread *cp)
for (idx = cp->c_data_offs; idx < cp->c_data_len; idx++) {
if (cp->sync_buf_offs >= cp->sync_key_len) break;
if (cp->c_data_ptr[idx] ==
- cp->sync_key_ptr[cp->sync_buf_offs]) {
+ cp->sync_key_ptr[cp->sync_buf_offs])
// Found the next key byte
(cp->sync_buf_offs)++;
- } else {
+ else
// Whoops, mismatched. Start key over...
cp->sync_buf_offs = 0;
- }
}
// Consume what we've walked through
@@ -360,10 +355,10 @@ static void pvr2_ioread_filter(struct pvr2_ioread *cp)
int pvr2_ioread_avail(struct pvr2_ioread *cp)
{
int ret;
- if (!(cp->enabled)) {
+
+ if (!cp->enabled)
// Stream is not enabled; so this is an I/O error
return -EIO;
- }
if (cp->sync_state == 1) {
pvr2_ioread_filter(cp);
@@ -372,15 +367,13 @@ int pvr2_ioread_avail(struct pvr2_ioread *cp)
ret = 0;
if (cp->stream_running) {
- if (!pvr2_stream_get_ready_count(cp->stream)) {
+ if (!pvr2_stream_get_ready_count(cp->stream))
// No data available at all right now.
ret = -EAGAIN;
- }
} else {
- if (pvr2_stream_get_ready_count(cp->stream) < BUFFER_COUNT/2) {
+ if (pvr2_stream_get_ready_count(cp->stream) < BUFFER_COUNT / 2)
// Haven't buffered up enough yet; try again later
ret = -EAGAIN;
- }
}
if ((!(cp->spigot_open)) != (!(ret == 0))) {
@@ -476,14 +469,13 @@ cp);
mutex_unlock(&cp->mutex);
if (!ret) {
- if (copied_cnt) {
+ if (copied_cnt)
// If anything was copied, return that count
ret = copied_cnt;
- } else {
+ else
// Nothing copied; suggest to caller that another
// attempt should be tried again later
ret = -EAGAIN;
- }
}
pvr2_trace(PVR2_TRACE_DATA_FLOW,
--
2.14.1
^ permalink raw reply related [flat|nested] 4+ messages in thread