Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1736751 > unrolled thread

[PATCH 0/4] [media] usbvision-core: Fine-tuning for some function implementations

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-09-21 17:10 +0200
Last post2017-09-21 17:20 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/4] [media] usbvision-core: Fine-tuning for some function  implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-09-21 17:10 +0200
    [PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in 11  functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-09-21 17:10 +0200
      Re: [PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in  11 functions Dan Carpenter <dan.carpenter@oracle.com> - 2017-09-22 13:50 +0200
        Re: [media] usbvision-core: Delete unnecessary braces in 11 functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-09-22 17:10 +0200
    [PATCH 4/4] [media] usbvision-core: Replace four printk() calls by  dev_err() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-09-21 17:20 +0200

#1736751 — [PATCH 0/4] [media] usbvision-core: Fine-tuning for some function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-09-21 17:10 +0200
Subject[PATCH 0/4] [media] usbvision-core: Fine-tuning for some function implementations
Message-ID<usbgZ-2CM-5@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 21 Sep 2017 17:00:17 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  Use common error handling code in usbvision_set_input()
  Use common error handling code in usbvision_set_compress_params()
  Delete unnecessary braces in 11 functions
  Replace four printk() calls by dev_err()

 drivers/media/usb/usbvision/usbvision-core.c | 128 ++++++++++++---------------
 1 file changed, 58 insertions(+), 70 deletions(-)

-- 
2.14.1

[toc] | [next] | [standalone]


#1736755 — [PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in 11 functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-09-21 17:10 +0200
Subject[PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in 11 functions
Message-ID<usbh0-2CM-15@gated-at.bofh.it>
In reply to#1736751
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 21 Sep 2017 16:24:20 +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/usbvision/usbvision-core.c | 71 ++++++++++++----------------
 1 file changed, 31 insertions(+), 40 deletions(-)

diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c
index bb6f4f69165f..54db35b03106 100644
--- a/drivers/media/usb/usbvision/usbvision-core.c
+++ b/drivers/media/usb/usbvision/usbvision-core.c
@@ -188,10 +188,9 @@ static int scratch_free(struct usb_usbvision *usbvision)
 	int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
 	if (free <= 0)
 		free += scratch_buf_size;
-	if (free) {
+	if (free)
 		free -= 1;							/* at least one byte in the buffer must */
 										/* left blank, otherwise there is no chance to differ between full and empty */
-	}
 	PDEBUG(DBG_SCRATCH, "return %d\n", free);
 
 	return free;
@@ -699,11 +698,12 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
 
 	frame = usbvision->cur_frame;
 	image_size = frame->frmwidth * frame->frmheight;
-	if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
-	    (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) {       /* this is a planar format */
+	if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P ||
+	    frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)
+		/* this is a planar format */
 		/* ... v4l2_linesize not used here. */
 		f = frame->data + (frame->width * frame->curline);
-	} else
+	else
 		f = frame->data + (frame->v4l2_linesize * frame->curline);
 
 	if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
@@ -734,22 +734,19 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
 		return parse_state_next_frame;
 	}
 
-	if (frame->curline != (int)strip_header[2]) {
+	if (frame->curline != (int)strip_header[2])
 		/* line number mismatch error */
 		usbvision->strip_line_number_errors++;
-	}
 
 	strip_len = 2 * (unsigned int)strip_header[1];
-	if (strip_len > USBVISION_STRIP_LEN_MAX) {
+	if (strip_len > USBVISION_STRIP_LEN_MAX)
 		/* strip overrun */
 		/* I think this never happens */
 		usbvision_request_intra(usbvision);
-	}
 
-	if (scratch_len(usbvision) < strip_len) {
+	if (scratch_len(usbvision) < strip_len)
 		/* there is not enough data for the strip */
 		return parse_state_out;
-	}
 
 	if (usbvision->intra_frame_buffer) {
 		Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline;
@@ -1306,11 +1303,11 @@ static void usbvision_isoc_irq(struct urb *urb)
 		/* If we collected enough data let's parse! */
 		if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH &&
 		    !list_empty(&(usbvision->inqueue))) {
-			if (!(*f)) {
+			if (!(*f))
 				(*f) = list_entry(usbvision->inqueue.next,
 						  struct usbvision_frame,
 						  frame);
-			}
+
 			usbvision_parse_data(usbvision);
 		} else {
 			/* If we don't have a frame
@@ -1334,12 +1331,10 @@ static void usbvision_isoc_irq(struct urb *urb)
 	urb->status = 0;
 	urb->dev = usbvision->dev;
 	err_code = usb_submit_urb(urb, GFP_ATOMIC);
-
-	if (err_code) {
+	if (err_code)
 		dev_err(&usbvision->dev->dev,
 			"%s: usb_submit_urb failed: error %d\n",
 				__func__, err_code);
-	}
 
 	return;
 }
@@ -1398,11 +1393,10 @@ int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
 				USB_DIR_OUT | USB_TYPE_VENDOR |
 				USB_RECIP_ENDPOINT, 0, (__u16) reg,
 				usbvision->ctrl_urb_buffer, 1, HZ);
-
-	if (err_code < 0) {
+	if (err_code < 0)
 		dev_err(&usbvision->dev->dev,
 			"%s: failed: error %d\n", __func__, err_code);
-	}
+
 	return err_code;
 }
 
@@ -1443,10 +1437,10 @@ static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address,
 	memcpy(usbvision->ctrl_urb_buffer, data, len);
 
 	err_code = usb_submit_urb(usbvision->ctrl_urb, GFP_ATOMIC);
-	if (err_code < 0) {
+	if (err_code < 0)
 		/* error in usb_submit_urb() */
 		usbvision->ctrl_urb_busy = 0;
-	}
+
 	PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, err_code);
 	return err_code;
 }
@@ -1477,11 +1471,11 @@ static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision)
 		usbvision->isoc_measure_bandwidth_count++;
 		return 0;
 	}
-	if ((usbvision->isoc_packet_size > 0) && (usbvision->isoc_packet_count > 0)) {
+	if (usbvision->isoc_packet_size > 0 && usbvision->isoc_packet_count > 0)
 		usbvision->used_bandwidth = usbvision->isoc_data_count /
 					(usbvision->isoc_packet_count + usbvision->isoc_skip_count) *
 					100 / usbvision->isoc_packet_size;
-	}
+
 	usbvision->isoc_measure_bandwidth_count = 0;
 	usbvision->isoc_data_count = 0;
 	usbvision->isoc_packet_count = 0;
@@ -1648,11 +1642,10 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
 			     USB_DIR_OUT | USB_TYPE_VENDOR |
 			     USB_RECIP_ENDPOINT, 0,
 			     (__u16) USBVISION_FILT_CONT, value, 2, HZ);
-
-	if (rc < 0) {
+	if (rc < 0)
 		printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
 		       proc, rc);
-	}
+
 	usbvision->isoc_mode = format;
 	return rc;
 }
@@ -1935,17 +1928,17 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
 		return 0;
 
 	/* Set input format expected from decoder*/
-	if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) {
+	if (usbvision_device_data[usbvision->dev_model].vin_reg1_override)
 		value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1;
-	} else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
+	else if (usbvision_device_data[usbvision->dev_model].codec
+		 == CODEC_SAA7113)
 		/* SAA7113 uses 8 bit output */
 		value[0] = USBVISION_8_422_SYNC;
-	} else {
+	else
 		/* I'm sure only about d2-d0 [010] 16 bit 4:2:2 usin sync pulses
 		 * as that is how saa7111 is configured */
 		value[0] = USBVISION_16_422_SYNC;
 		/* | USBVISION_VSNC_POL | USBVISION_VCLK_POL);*/
-	}
 
 	rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]);
 	if (rc < 0)
@@ -2015,12 +2008,12 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
 
 	dvi_yuv_value = 0x00;	/* U comes after V, Ya comes after U/V, Yb comes after Yb */
 
-	if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) {
+	if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override)
 		dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv;
-	} else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
+	else if (usbvision_device_data[usbvision->dev_model].codec
+		 == CODEC_SAA7113)
 		/* This changes as the fine sync control changes. Further investigation necessary */
 		dvi_yuv_value = 0x06;
-	}
 
 	return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value);
 
@@ -2320,11 +2313,10 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
 	for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
 		err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb,
 					 GFP_KERNEL);
-		if (err_code) {
+		if (err_code)
 			dev_err(&usbvision->dev->dev,
 				"%s: usb_submit_urb(%d) failed: error %d\n",
 					__func__, buf_idx, err_code);
-		}
 	}
 
 	usbvision->streaming = stream_idle;
@@ -2352,12 +2344,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
 	/* Unschedule all of the iso td's */
 	for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
 		usb_kill_urb(usbvision->sbuf[buf_idx].urb);
-		if (usbvision->sbuf[buf_idx].data) {
+		if (usbvision->sbuf[buf_idx].data)
 			usb_free_coherent(usbvision->dev,
 					  sb_size,
 					  usbvision->sbuf[buf_idx].data,
 					  usbvision->sbuf[buf_idx].urb->transfer_dma);
-		}
+
 		usb_free_urb(usbvision->sbuf[buf_idx].urb);
 		usbvision->sbuf[buf_idx].urb = NULL;
 	}
@@ -2409,14 +2401,13 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
 	switch (usbvision_device_data[usbvision->dev_model].codec) {
 	case CODEC_SAA7113:
 		mode[1] = SAA7115_COMPOSITE2;
-		if (switch_svideo_input) {
+		if (switch_svideo_input)
 			/* To handle problems with S-Video Input for
 			 * some devices.  Use switch_svideo_input
 			 * parameter when loading the module.*/
 			mode[2] = SAA7115_COMPOSITE1;
-		} else {
+		else
 			mode[2] = SAA7115_SVIDEO1;
-		}
 		break;
 	case CODEC_SAA7111:
 	default:
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1737428 — Re: [PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in 11 functions

FromDan Carpenter <dan.carpenter@oracle.com>
Date2017-09-22 13:50 +0200
SubjectRe: [PATCH 3/4] [media] usbvision-core: Delete unnecessary braces in 11 functions
Message-ID<usuCZ-5Be-3@gated-at.bofh.it>
In reply to#1736755
No.  Multi-line indents get curly braces for readability.

regards,
dan carpenter

[toc] | [prev] | [next] | [standalone]


#1737572 — Re: [media] usbvision-core: Delete unnecessary braces in 11 functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-09-22 17:10 +0200
SubjectRe: [media] usbvision-core: Delete unnecessary braces in 11 functions
Message-ID<usxKz-7Bl-47@gated-at.bofh.it>
In reply to#1737428
> No.  Multi-line indents get curly braces for readability.

Which of the proposed change possibilities do you not like especially at the moment?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1736767 — [PATCH 4/4] [media] usbvision-core: Replace four printk() calls by dev_err()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-09-21 17:20 +0200
Subject[PATCH 4/4] [media] usbvision-core: Replace four printk() calls by dev_err()
Message-ID<usbqG-2Ji-25@gated-at.bofh.it>
In reply to#1736751
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 21 Sep 2017 16:47:28 +0200

* Replace the local variable "proc" by the identifier "__func__".

* Use the interface "dev_err" instead of "printk" in these functions.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/usbvision/usbvision-core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c
index 54db35b03106..2c98805244df 100644
--- a/drivers/media/usb/usbvision/usbvision-core.c
+++ b/drivers/media/usb/usbvision/usbvision-core.c
@@ -1619,7 +1619,6 @@ static int usbvision_init_webcam(struct usb_usbvision *usbvision)
  */
 static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format)
 {
-	static const char proc[] = "usbvision_set_video_format";
 	unsigned char *value = usbvision->ctrl_urb_buffer;
 	int rc;
 
@@ -1631,8 +1630,9 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
 	if ((format != ISOC_MODE_YUV422)
 	    && (format != ISOC_MODE_YUV420)
 	    && (format != ISOC_MODE_COMPRESS)) {
-		printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420",
-		       format);
+		dev_err(&usbvision->dev->dev,
+			"%s: unknown video format %02x, using default YUV420\n",
+			__func__, format);
 		format = ISOC_MODE_YUV420;
 	}
 	value[0] = 0x0A;  /* TODO: See the effect of the filter */
@@ -1643,8 +1643,9 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
 			     USB_RECIP_ENDPOINT, 0,
 			     (__u16) USBVISION_FILT_CONT, value, 2, HZ);
 	if (rc < 0)
-		printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
-		       proc, rc);
+		dev_err(&usbvision->dev->dev,
+			"%s: ERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
+			__func__, rc);
 
 	usbvision->isoc_mode = format;
 	return rc;
@@ -2180,7 +2181,8 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
 int usbvision_audio_off(struct usb_usbvision *usbvision)
 {
 	if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
-		printk(KERN_ERR "usbvision_audio_off: can't write reg\n");
+		dev_err(&usbvision->dev->dev,
+			"%s: can't write reg\n", __func__);
 		return -1;
 	}
 	usbvision->audio_mute = 0;
@@ -2192,7 +2194,9 @@ int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel)
 {
 	if (!usbvision->audio_mute) {
 		if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, audio_channel) < 0) {
-			printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n");
+			dev_err(&usbvision->dev->dev,
+				"%s: can't write iopin register for audio switching\n",
+				__func__);
 			return -1;
 		}
 	}
-- 
2.14.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web