Skip to contentSkip to conversation

staging: media: Misc driver Cleanup

PATCH New Sam Muhammed 1 participant 4 messages Apr 6, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover staging: media: Misc driver Cleanup

Modifications:
- Clean kernel messages with dev_err()
- Remove Comparison with NULL
- Use dev_*() family for printing kernel
messages

Basically changes are made to silence some
Checkpatch.pl WARNINGs, and modify the code
to be more readable.

Sam Muhammed (3):
staging: media: Clean dev_err() message
staging: media: Avoid comparison to NULL
staging: media: Use dev_*() family

 drivers/staging/media/imx/imx-media-utils.c   |  2 +-
 drivers/staging/media/meson/vdec/esparser.c   |  2 +-
 drivers/staging/media/soc_camera/soc_ov5642.c |  9 +--
 .../staging/media/usbvision/usbvision-core.c  | 71 ++++++++++---------
 .../staging/media/usbvision/usbvision-i2c.c   |  7 +-
 .../staging/media/usbvision/usbvision-video.c | 41 ++++++-----
 6 files changed, 66 insertions(+), 66 deletions(-)

---
2.20.1

#1 lore raw

PATCH 1/3 staging: media: Clean dev_err() message

dev_err() already provides information about the associated device, there is no need to include __func__ in the message, so remove it with the %s format string to be consistent.

---
 drivers/staging/media/imx/imx-media-utils.c   |  2 +-
 drivers/staging/media/meson/vdec/esparser.c   |  2 +-
 drivers/staging/media/soc_camera/soc_ov5642.c |  9 +++----
 .../staging/media/usbvision/usbvision-core.c  | 27 +++++++++----------
 .../staging/media/usbvision/usbvision-video.c | 27 +++++++++----------
 5 files changed, 29 insertions(+), 38 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +1 -1
index fae981698c49..8816ac1595bd 100644
@@ -700,7 +700,7 @@ int imx_media_alloc_dma_buf(struct device *dev,
 	buf->virt = dma_alloc_coherent(dev, buf->len, &buf->phys,
 				       GFP_DMA | GFP_KERNEL);
 	if (!buf->virt) {
-		dev_err(dev, "%s: failed\n", __func__);
+		dev_err(dev, "failed\n");
 		return -ENOMEM;
 	}
 
drivers/staging/media/meson/vdec/esparser.c +1 -1
index db7022707ff8..ab31d280039d 100644
@@ -173,7 +173,7 @@ static int vp9_update_header(struct amvdec_core *core, struct vb2_buffer *buf)
 			memset(fdata + 16 + framesize, 0,
 			       (old_header - fdata + 16 + framesize));
 		} else if (old_header < fdata + 16 + framesize) {
-			dev_err(core->dev, "%s: data overwritten\n", __func__);
+			dev_err(core->dev, "data overwritten\n");
 		}
 		old_header = fdata;
 	}
drivers/staging/media/soc_camera/soc_ov5642.c +3 -6
index 39ae24dca65f..3c58bc009e42 100644
@@ -643,15 +643,13 @@ static int reg_read(struct i2c_client *client, u16 reg, u8 *val)
 
 	ret = i2c_master_send(client, data, 2);
 	if (ret < 2) {
-		dev_err(&client->dev, "%s: i2c read error, reg: %x\n",
-			__func__, reg);
+		dev_err(&client->dev, "i2c read error, reg: %x\n", reg);
 		return ret < 0 ? ret : -EIO;
 	}
 
 	ret = i2c_master_recv(client, val, 1);
 	if (ret < 1) {
-		dev_err(&client->dev, "%s: i2c read error, reg: %x\n",
-				__func__, reg);
+		dev_err(&client->dev, "i2c read error, reg: %x\n", reg);
 		return ret < 0 ? ret : -EIO;
 	}
 	return 0;
@@ -664,8 +662,7 @@ static int reg_write(struct i2c_client *client, u16 reg, u8 val)
 
 	ret = i2c_master_send(client, data, 3);
 	if (ret < 3) {
-		dev_err(&client->dev, "%s: i2c write error, reg: %x\n",
-			__func__, reg);
+		dev_err(&client->dev, "i2c write error, reg: %x\n", reg);
 		return ret < 0 ? ret : -EIO;
 	}
 
drivers/staging/media/usbvision/usbvision-core.c +12 -15
index f05a5c84dc18..b84a77f7739a 100644
@@ -351,8 +351,8 @@ int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
 	scratch_reset(usbvision);
 	if (usbvision->scratch == NULL) {
 		dev_err(&usbvision->dev->dev,
-			"%s: unable to allocate %d bytes for scratch\n",
-				__func__, scratch_buf_size);
+			"unable to allocate %d bytes for scratch\n",
+			scratch_buf_size);
 		return -ENOMEM;
 	}
 	return 0;
@@ -376,8 +376,8 @@ int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
 	usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
 	if (usbvision->intra_frame_buffer == NULL) {
 		dev_err(&usbvision->dev->dev,
-			"%s: unable to allocate %d for compr. frame buffer\n",
-				__func__, IFB_size);
+			"unable to allocate %d for compr. frame buffer\n",
+			IFB_size);
 		return -ENOMEM;
 	}
 	return 0;
@@ -1324,8 +1324,7 @@ static void usbvision_isoc_irq(struct urb *urb)
 
 	if (err_code) {
 		dev_err(&usbvision->dev->dev,
-			"%s: usb_submit_urb failed: error %d\n",
-				__func__, err_code);
+			"usb_submit_urb failed: error %d\n", err_code);
 	}
 
 	return;
@@ -1356,8 +1355,7 @@ int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
 				0, (__u16) reg, buffer, 1, HZ);
 
 	if (err_code < 0) {
-		dev_err(&usbvision->dev->dev,
-			"%s: failed: error %d\n", __func__, err_code);
+		dev_err(&usbvision->dev->dev, "failed: error %d\n", err_code);
 		return err_code;
 	}
 	return buffer[0];
@@ -1387,8 +1385,7 @@ int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
 				usbvision->ctrl_urb_buffer, 1, HZ);
 
 	if (err_code < 0) {
-		dev_err(&usbvision->dev->dev,
-			"%s: failed: error %d\n", __func__, err_code);
+		dev_err(&usbvision->dev->dev, "failed: error %d\n", err_code);
 	}
 	return err_code;
 }
@@ -1698,8 +1695,8 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
 				 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
 
 		if (err_code < 0) {
-			dev_err(&usbvision->dev->dev,
-				"%s failed: error %d\n", __func__, err_code);
+			dev_err(&usbvision->dev->dev, "failed: error %d\n",
+				err_code);
 			return err_code;
 		}
 		usbvision->curwidth = usbvision->stretch_width * usb_width;
@@ -2084,7 +2081,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
 			     (__u16) USBVISION_DRM_PRM1, value, 8, HZ);
 
 	if (rc < 0) {
-		dev_err(&usbvision->dev->dev, "%s: ERROR=%d\n", __func__, rc);
+		dev_err(&usbvision->dev->dev, "ERROR=%d\n", rc);
 		return rc;
 	}
 
@@ -2369,8 +2366,8 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
 					    usbvision->iface_alt);
 		if (err_code < 0) {
 			dev_err(&usbvision->dev->dev,
-				"%s: usb_set_interface() failed: error %d\n",
-					__func__, err_code);
+				"usb_set_interface() failed: error %d\n",
+				err_code);
 			usbvision->last_error = err_code;
 		}
 		reg_value = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
drivers/staging/media/usbvision/usbvision-video.c +12 -15
index 3ea25fdcf767..edf34497aae7 100644
@@ -278,7 +278,7 @@ static void usbvision_create_sysfs(struct video_device *vdev)
 			return;
 	} while (0);
 
-	dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
+	dev_err(&vdev->dev, "error: %d\n", res);
 }
 
 static void usbvision_remove_sysfs(struct video_device *vdev)
@@ -427,8 +427,7 @@ static int vidioc_g_register(struct file *file, void *priv,
 	err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
 	if (err_code < 0) {
 		dev_err(&usbvision->vdev.dev,
-			"%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
-				__func__, err_code);
+			"VIDIOC_DBG_G_REGISTER failed: error %d\n", err_code);
 		return err_code;
 	}
 	reg->val = err_code;
@@ -446,8 +445,7 @@ static int vidioc_s_register(struct file *file, void *priv,
 	err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
 	if (err_code < 0) {
 		dev_err(&usbvision->vdev.dev,
-			"%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
-				__func__, err_code);
+			"VIDIOC_DBG_S_REGISTER failed: error %d\n", err_code);
 		return err_code;
 	}
 	return 0;
@@ -1080,8 +1078,7 @@ static int usbvision_radio_open(struct file *file)
 		goto out;
 	if (usbvision->user) {
 		dev_err(&usbvision->rdev.dev,
-			"%s: Someone tried to open an already opened USBVision Radio!\n",
-				__func__);
+			"Someone tried to open an already opened USBVision Radio!\n");
 		err_code = -EBUSY;
 	} else {
 		/* Alternate interface 1 is is the biggest frame size */
@@ -1223,7 +1220,7 @@ static void usbvision_vdev_init(struct usb_usbvision *usbvision,
 
 	if (!usb_dev) {
 		dev_err(&usbvision->dev->dev,
-			"%s: usbvision->dev is not set\n", __func__);
+			"usbvision->dev is not set\n");
 		return;
 	}
 
@@ -1452,23 +1449,23 @@ static int usbvision_probe(struct usb_interface *intf,
 	endpoint = &interface->endpoint[1].desc;
 
 	if (!usb_endpoint_xfer_isoc(endpoint)) {
-		dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
-		    __func__, ifnum);
-		dev_err(&intf->dev, "%s: Endpoint attributes %d",
-		    __func__, endpoint->bmAttributes);
+		dev_err(&intf->dev, "interface %d. has non-ISO endpoint!\n",
+			ifnum);
+		dev_err(&intf->dev, "Endpoint attributes %d",
+			endpoint->bmAttributes);
 		ret = -ENODEV;
 		goto err_usb;
 	}
 	if (usb_endpoint_dir_out(endpoint)) {
-		dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
-		    __func__, ifnum);
+		dev_err(&intf->dev, "interface %d. has ISO OUT endpoint!\n",
+			ifnum);
 		ret = -ENODEV;
 		goto err_usb;
 	}
 
 	usbvision = usbvision_alloc(dev, intf);
 	if (!usbvision) {
-		dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
+		dev_err(&intf->dev, "couldn't allocate USBVision struct\n");
 		ret = -ENOMEM;
 		goto err_usb;
 	}

---
2.20.1

#2 lore raw

PATCH 2/3 staging: media: Avoid comparison to NULL

In reply to Sam Muhammed

Comparison to NULL should be avoided,
use (!x) instead to follow the coding standards.

Used a custom coccinelle script:

@@
expression e;
@@

-(e == NULL)
+!e

---
 drivers/staging/media/usbvision/usbvision-core.c | 8 ++++----
 drivers/staging/media/usbvision/usbvision-i2c.c  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/media/usbvision/usbvision-core.c +4 -4
index b84a77f7739a..284bda783c2b 100644
@@ -349,7 +349,7 @@ int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
 {
 	usbvision->scratch = vmalloc_32(scratch_buf_size);
 	scratch_reset(usbvision);
-	if (usbvision->scratch == NULL) {
+	if (!usbvision->scratch) {
 		dev_err(&usbvision->dev->dev,
 			"unable to allocate %d bytes for scratch\n",
 			scratch_buf_size);
@@ -374,7 +374,7 @@ int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
 	int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
 
 	usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
-	if (usbvision->intra_frame_buffer == NULL) {
+	if (!usbvision->intra_frame_buffer) {
 		dev_err(&usbvision->dev->dev,
 			"unable to allocate %d for compr. frame buffer\n",
 			IFB_size);
@@ -2281,7 +2281,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
 		struct urb *urb;
 
 		urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
-		if (urb == NULL)
+		if (!urb)
 			return -ENOMEM;
 		usbvision->sbuf[buf_idx].urb = urb;
 		usbvision->sbuf[buf_idx].data =
@@ -2340,7 +2340,7 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
 	int buf_idx, err_code, reg_value;
 	int sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size;
 
-	if ((usbvision->streaming == stream_off) || (usbvision->dev == NULL))
+	if ((usbvision->streaming == stream_off) || !usbvision->dev)
 		return;
 
 	/* Unschedule all of the iso td's */
drivers/staging/media/usbvision/usbvision-i2c.c +1 -1
index 6e4df3335b1b..3bba93293463 100644
@@ -233,7 +233,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
 				&usbvision->i2c_adap,
 				"tuner", 0, v4l2_i2c_tuner_addrs(type));
 
-		if (sd == NULL)
+		if (!sd)
 			return -ENODEV;
 		if (usbvision->tuner_type != -1) {
 			tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;

---
2.20.1

#3 lore raw

PATCH 3/3 staging: media: Use dev_*() family

In reply to Sam Muhammed

dev_*() family provide information specific to the associated device, use them instead of printk(KERN_LEVEL ...) to be consistent.

This patch fixes Checkpatch.pl WARNINGS:
Prefer [subsystem eg: netdev]_info([subsystem]dev, ... then dev_info(dev, ... then pr_info(... to printk(KERN_INFO ...

Prefer [subsystem eg: netdev]_err([subsystem]dev, ... then dev_err(dev, ... then pr_err(... to printk(KERN_ERR ...

---
 .../staging/media/usbvision/usbvision-core.c  | 36 +++++++++++--------
 .../staging/media/usbvision/usbvision-i2c.c   |  5 ++-
 .../staging/media/usbvision/usbvision-video.c | 14 ++++----
 3 files changed, 32 insertions(+), 23 deletions(-)
drivers/staging/media/usbvision/usbvision-core.c +22 -14
index 284bda783c2b..9373e8472247 100644
@@ -1621,8 +1621,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,
+			"usbvision: unknown video format %02x, using default YUV420",
+			format);
 		format = ISOC_MODE_YUV420;
 	}
 	value[0] = 0x0A;  /* TODO: See the effect of the filter */
@@ -1634,8 +1635,9 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
 			     (__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",
+			proc, rc);
 	}
 	usbvision->isoc_mode = format;
 	return rc;
@@ -1868,8 +1870,9 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
 			     (__u16) USBVISION_INTRA_CYC, value, 5, HZ);
 
 	if (rc < 0) {
-		printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
-		       proc, rc);
+		dev_err(&usbvision->dev->dev,
+			"%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
+			proc, rc);
 		return rc;
 	}
 
@@ -1899,8 +1902,9 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
 			     (__u16) USBVISION_PCM_THR1, value, 6, HZ);
 
 	if (rc < 0) {
-		printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
-		       proc, rc);
+		dev_err(&usbvision->dev->dev,
+			"%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
+			proc, rc);
 	}
 	return rc;
 }
@@ -1938,8 +1942,9 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
 
 	rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]);
 	if (rc < 0) {
-		printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
-		       proc, rc);
+		dev_err(&usbvision->dev->dev,
+			"%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
+			proc, rc);
 		return rc;
 	}
 
@@ -2004,8 +2009,9 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
 			     USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0,
 			     (__u16) USBVISION_LXSIZE_I, value, 8, HZ);
 	if (rc < 0) {
-		printk(KERN_ERR "%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
-		       proc, rc);
+		dev_err(&usbvision->dev->dev,
+			"%sERROR=%d. USBVISION stopped - reconnect or reload driver.\n",
+			proc, rc);
 		return rc;
 	}
 
@@ -2178,7 +2184,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,
+			"usbvision_audio_off: can't write reg\n");
 		return -1;
 	}
 	usbvision->audio_mute = 0;
@@ -2190,7 +2197,8 @@ 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,
+				"can't write iopin register for audio switching\n");
 			return -1;
 		}
 	}
drivers/staging/media/usbvision/usbvision-i2c.c +2 -3
index 3bba93293463..4f6672766ae4 100644
@@ -187,7 +187,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
 	i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev);
 
 	if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
-		printk(KERN_ERR "usbvision_i2c_register: can't write reg\n");
+		dev_err(&usbvision->dev->dev, "can't write reg\n");
 		return -EBUSY;
 	}
 
@@ -314,8 +314,7 @@ usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr,
 		buf[0] = usbvision_read_reg(usbvision, USBVISION_SER_DAT1);
 		break;
 	default:
-		printk(KERN_ERR
-		       "usbvision_i2c_read_max4: buffer length > 4\n");
+		dev_err(&usbvision->dev->dev, "buffer length > 4\n");
 	}
 
 	if (i2c_debug & DBG_I2C) {
drivers/staging/media/usbvision/usbvision-video.c +8 -6
index edf34497aae7..28614ab56f8f 100644
@@ -1270,8 +1270,9 @@ static int usbvision_register_video(struct usb_usbvision *usbvision)
 
 	if (video_register_device(&usbvision->vdev, VFL_TYPE_VIDEO, video_nr) < 0)
 		goto err_exit;
-	printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
-	       usbvision->nr, video_device_node_name(&usbvision->vdev));
+	dev_info(&usbvision->dev->dev,
+		 "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
+		 usbvision->nr, video_device_node_name(&usbvision->vdev));
 
 	/* Radio Device: */
 	if (usbvision_device_data[usbvision->dev_model].radio) {
@@ -1281,8 +1282,9 @@ static int usbvision_register_video(struct usb_usbvision *usbvision)
 		usbvision->rdev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
 		if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
 			goto err_exit;
-		printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
-		       usbvision->nr, video_device_node_name(&usbvision->rdev));
+		dev_info(&usbvision->dev->dev,
+			 "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
+			 usbvision->nr, video_device_node_name(&usbvision->rdev));
 	}
 	/* all done */
 	return 0;
@@ -1426,8 +1428,8 @@ static int usbvision_probe(struct usb_interface *intf,
 		ret = -ENODEV;
 		goto err_usb;
 	}
-	printk(KERN_INFO "%s: %s found\n", __func__,
-				usbvision_device_data[model].model_string);
+	dev_info(&intf->dev, "%s found\n",
+		 usbvision_device_data[model].model_string);
 
 	if (usbvision_device_data[model].interface >= 0)
 		interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];

---
2.20.1