Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: Prefer designated initializers over memset for subdev pad ops

Structures passed to subdev pad operations are all zero-initialized, but
not always with the same kind of code constructs. While most drivers
used designated initializers, which zero all the fields that are not
specified, when declaring variables, some use memset(). Those two
methods lead to the same end result, and, depending on compiler
optimizations, may even be completely equivalent, but they're not
consistent.

Improve coding style consistency by using designated initializers
instead of calling memset(). Where applicable, also move the variables
to inner scopes of for loops to ensure correct initialization in all
iterations.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Lad Prabhakar <prabhakar.csengg@gmail.com> # For am437x
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Laurent Pinchart and committed by
Hans Verkuil
e3a69496 ecefa105

+50 -49
+9 -9
drivers/media/platform/renesas/vsp1/vsp1_drm.c
··· 66 66 struct vsp1_entity *prev, unsigned int prev_pad, 67 67 struct vsp1_entity *next, unsigned int next_pad) 68 68 { 69 - struct v4l2_subdev_format format; 69 + struct v4l2_subdev_format format = { 70 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 71 + }; 70 72 int ret; 71 73 72 74 if (!uif) { ··· 84 82 prev->sink = uif; 85 83 prev->sink_pad = UIF_PAD_SINK; 86 84 87 - memset(&format, 0, sizeof(format)); 88 - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; 89 85 format.pad = prev_pad; 90 86 91 87 ret = v4l2_subdev_call(&prev->subdev, pad, get_fmt, NULL, &format); ··· 118 118 struct vsp1_entity *uif, 119 119 unsigned int brx_input) 120 120 { 121 - struct v4l2_subdev_selection sel; 122 - struct v4l2_subdev_format format; 121 + struct v4l2_subdev_selection sel = { 122 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 123 + }; 124 + struct v4l2_subdev_format format = { 125 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 126 + }; 123 127 const struct v4l2_rect *crop; 124 128 int ret; 125 129 ··· 133 129 */ 134 130 crop = &vsp1->drm->inputs[rpf->entity.index].crop; 135 131 136 - memset(&format, 0, sizeof(format)); 137 - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; 138 132 format.pad = RWPF_PAD_SINK; 139 133 format.format.width = crop->width + crop->left; 140 134 format.format.height = crop->height + crop->top; ··· 149 147 __func__, format.format.width, format.format.height, 150 148 format.format.code, rpf->entity.index); 151 149 152 - memset(&sel, 0, sizeof(sel)); 153 - sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; 154 150 sel.pad = RWPF_PAD_SINK; 155 151 sel.target = V4L2_SEL_TGT_CROP; 156 152 sel.r = *crop;
+5 -6
drivers/media/platform/renesas/vsp1/vsp1_entity.c
··· 184 184 int vsp1_entity_init_cfg(struct v4l2_subdev *subdev, 185 185 struct v4l2_subdev_state *sd_state) 186 186 { 187 - struct v4l2_subdev_format format; 188 187 unsigned int pad; 189 188 190 189 for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) { 191 - memset(&format, 0, sizeof(format)); 192 - 193 - format.pad = pad; 194 - format.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY 195 - : V4L2_SUBDEV_FORMAT_ACTIVE; 190 + struct v4l2_subdev_format format = { 191 + .pad = pad, 192 + .which = sd_state ? V4L2_SUBDEV_FORMAT_TRY 193 + : V4L2_SUBDEV_FORMAT_ACTIVE, 194 + }; 196 195 197 196 v4l2_subdev_call(subdev, pad, set_fmt, sd_state, &format); 198 197 }
+4 -3
drivers/media/platform/samsung/exynos4-is/fimc-capture.c
··· 763 763 struct fimc_dev *fimc = ctx->fimc_dev; 764 764 struct fimc_pipeline *p = to_fimc_pipeline(fimc->vid_cap.ve.pipe); 765 765 struct v4l2_subdev *sd = p->subdevs[IDX_SENSOR]; 766 - struct v4l2_subdev_format sfmt; 766 + struct v4l2_subdev_format sfmt = { 767 + .which = set ? V4L2_SUBDEV_FORMAT_ACTIVE 768 + : V4L2_SUBDEV_FORMAT_TRY, 769 + }; 767 770 struct v4l2_mbus_framefmt *mf = &sfmt.format; 768 771 struct media_entity *me; 769 772 struct fimc_fmt *ffmt; ··· 777 774 if (WARN_ON(!sd || !tfmt)) 778 775 return -EINVAL; 779 776 780 - memset(&sfmt, 0, sizeof(sfmt)); 781 777 sfmt.format = *tfmt; 782 - sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; 783 778 784 779 me = fimc_pipeline_get_head(&sd->entity); 785 780
+8 -7
drivers/media/platform/ti/am437x/am437x-vpfe.c
··· 1501 1501 struct v4l2_frmsizeenum *fsize) 1502 1502 { 1503 1503 struct vpfe_device *vpfe = video_drvdata(file); 1504 - struct v4l2_subdev_frame_size_enum fse; 1504 + struct v4l2_subdev_frame_size_enum fse = { 1505 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 1506 + }; 1505 1507 struct v4l2_subdev *sd = vpfe->current_subdev->sd; 1506 1508 struct vpfe_fmt *fmt; 1507 1509 int ret; ··· 1518 1516 1519 1517 memset(fsize->reserved, 0x0, sizeof(fsize->reserved)); 1520 1518 1521 - memset(&fse, 0x0, sizeof(fse)); 1522 1519 fse.index = fsize->index; 1523 1520 fse.pad = 0; 1524 1521 fse.code = fmt->code; 1525 - fse.which = V4L2_SUBDEV_FORMAT_ACTIVE; 1526 1522 ret = v4l2_subdev_call(sd, pad, enum_frame_size, NULL, &fse); 1527 1523 if (ret) 1528 1524 return ret; ··· 2148 2148 { 2149 2149 struct vpfe_device *vpfe = container_of(notifier->v4l2_dev, 2150 2150 struct vpfe_device, v4l2_dev); 2151 - struct v4l2_subdev_mbus_code_enum mbus_code; 2152 2151 struct vpfe_subdev_info *sdinfo; 2153 2152 struct vpfe_fmt *fmt; 2154 2153 int ret = 0; ··· 2174 2175 2175 2176 vpfe->num_active_fmt = 0; 2176 2177 for (j = 0, i = 0; (ret != -EINVAL); ++j) { 2177 - memset(&mbus_code, 0, sizeof(mbus_code)); 2178 - mbus_code.index = j; 2179 - mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE; 2178 + struct v4l2_subdev_mbus_code_enum mbus_code = { 2179 + .index = j, 2180 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 2181 + }; 2182 + 2180 2183 ret = v4l2_subdev_call(subdev, pad, enum_mbus_code, 2181 2184 NULL, &mbus_code); 2182 2185 if (ret)
+4 -4
drivers/media/platform/ti/cal/cal-video.c
··· 814 814 815 815 static int cal_ctx_v4l2_init_formats(struct cal_ctx *ctx) 816 816 { 817 - struct v4l2_subdev_mbus_code_enum mbus_code; 818 817 struct v4l2_mbus_framefmt mbus_fmt; 819 818 const struct cal_format_info *fmtinfo; 820 819 unsigned int i, j, k; ··· 828 829 ctx->num_active_fmt = 0; 829 830 830 831 for (j = 0, i = 0; ; ++j) { 832 + struct v4l2_subdev_mbus_code_enum mbus_code = { 833 + .index = j, 834 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 835 + }; 831 836 832 - memset(&mbus_code, 0, sizeof(mbus_code)); 833 - mbus_code.index = j; 834 - mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE; 835 837 ret = v4l2_subdev_call(ctx->phy->source, pad, enum_mbus_code, 836 838 NULL, &mbus_code); 837 839 if (ret == -EINVAL)
+7 -7
drivers/media/usb/dvb-usb/cxusb-analog.c
··· 1014 1014 { 1015 1015 struct dvb_usb_device *dvbdev = video_drvdata(file); 1016 1016 struct cxusb_medion_dev *cxdev = dvbdev->priv; 1017 - struct v4l2_subdev_format subfmt; 1017 + struct v4l2_subdev_format subfmt = { 1018 + .which = isset ? V4L2_SUBDEV_FORMAT_ACTIVE : 1019 + V4L2_SUBDEV_FORMAT_TRY, 1020 + }; 1018 1021 u32 field; 1019 1022 int ret; 1020 1023 ··· 1027 1024 field = vb2_start_streaming_called(&cxdev->videoqueue) ? 1028 1025 cxdev->field_order : cxusb_medion_field_order(cxdev); 1029 1026 1030 - memset(&subfmt, 0, sizeof(subfmt)); 1031 - subfmt.which = isset ? V4L2_SUBDEV_FORMAT_ACTIVE : 1032 - V4L2_SUBDEV_FORMAT_TRY; 1033 1027 subfmt.format.width = f->fmt.pix.width & ~1; 1034 1028 subfmt.format.height = f->fmt.pix.height & ~1; 1035 1029 subfmt.format.code = MEDIA_BUS_FMT_FIXED; ··· 1464 1464 .buf = tuner_analog_msg_data, 1465 1465 .len = 1466 1466 sizeof(tuner_analog_msg_data) }; 1467 - struct v4l2_subdev_format subfmt; 1467 + struct v4l2_subdev_format subfmt = { 1468 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 1469 + }; 1468 1470 int ret; 1469 1471 1470 1472 /* switch tuner to analog mode so IF demod will become accessible */ ··· 1509 1507 v4l2_subdev_call(cxdev->tuner, video, s_std, cxdev->norm); 1510 1508 v4l2_subdev_call(cxdev->cx25840, video, s_std, cxdev->norm); 1511 1509 1512 - memset(&subfmt, 0, sizeof(subfmt)); 1513 - subfmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 1514 1510 subfmt.format.width = cxdev->width; 1515 1511 subfmt.format.height = cxdev->height; 1516 1512 subfmt.format.code = MEDIA_BUS_FMT_FIXED;
+6 -6
drivers/staging/media/imx/imx-media-capture.c
··· 504 504 struct v4l2_streamparm *a) 505 505 { 506 506 struct capture_priv *priv = video_drvdata(file); 507 - struct v4l2_subdev_frame_interval fi; 507 + struct v4l2_subdev_frame_interval fi = { 508 + .pad = priv->src_sd_pad, 509 + }; 508 510 int ret; 509 511 510 512 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 511 513 return -EINVAL; 512 514 513 - memset(&fi, 0, sizeof(fi)); 514 - fi.pad = priv->src_sd_pad; 515 515 ret = v4l2_subdev_call(priv->src_sd, video, g_frame_interval, &fi); 516 516 if (ret < 0) 517 517 return ret; ··· 526 526 struct v4l2_streamparm *a) 527 527 { 528 528 struct capture_priv *priv = video_drvdata(file); 529 - struct v4l2_subdev_frame_interval fi; 529 + struct v4l2_subdev_frame_interval fi = { 530 + .pad = priv->src_sd_pad, 531 + }; 530 532 int ret; 531 533 532 534 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 533 535 return -EINVAL; 534 536 535 - memset(&fi, 0, sizeof(fi)); 536 - fi.pad = priv->src_sd_pad; 537 537 fi.interval = a->parm.capture.timeperframe; 538 538 ret = v4l2_subdev_call(priv->src_sd, video, s_frame_interval, &fi); 539 539 if (ret < 0)
+4 -4
drivers/staging/media/imx/imx-media-utils.c
··· 432 432 struct v4l2_subdev_state *sd_state) 433 433 { 434 434 struct v4l2_mbus_framefmt *mf_try; 435 - struct v4l2_subdev_format format; 436 435 unsigned int pad; 437 436 int ret; 438 437 439 438 for (pad = 0; pad < sd->entity.num_pads; pad++) { 440 - memset(&format, 0, sizeof(format)); 439 + struct v4l2_subdev_format format = { 440 + .pad = pad, 441 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 442 + }; 441 443 442 - format.pad = pad; 443 - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; 444 444 ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); 445 445 if (ret) 446 446 continue;
+3 -3
drivers/staging/media/omap4iss/iss_video.c
··· 237 237 __iss_video_get_format(struct iss_video *video, 238 238 struct v4l2_mbus_framefmt *format) 239 239 { 240 - struct v4l2_subdev_format fmt; 240 + struct v4l2_subdev_format fmt = { 241 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 242 + }; 241 243 struct v4l2_subdev *subdev; 242 244 u32 pad; 243 245 int ret; ··· 248 246 if (!subdev) 249 247 return -EINVAL; 250 248 251 - memset(&fmt, 0, sizeof(fmt)); 252 249 fmt.pad = pad; 253 - fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 254 250 255 251 mutex_lock(&video->mutex); 256 252 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);