summaryrefslogtreecommitdiff
path: root/drivers/media/platform/ti/omap3isp/ispvideo.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2023-02-15 18:18:39 +0300
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2023-04-12 10:46:06 +0300
commitecefa105cc44fff6d170ac5f441e76cb229f8e19 (patch)
tree40b1d8cb135dfaf82846f6aa1f4e620ac81bc322 /drivers/media/platform/ti/omap3isp/ispvideo.c
parenta8ca0cf1ff53c011e7654c4c2e9c1bcf297204b3 (diff)
downloadlinux-ecefa105cc44fff6d170ac5f441e76cb229f8e19.tar.xz
media: Zero-initialize all structures passed to subdev pad operations
Several drivers call subdev pad operations, passing structures that are not fully zeroed. While the drivers initialize the fields they care about explicitly, this results in reserved fields having uninitialized values. Future kernel API changes that make use of those fields thus risk breaking proper driver operation in ways that could be hard to detect. To avoid this, make the code more robust by zero-initializing all the structures passed to subdev pad operation. Maintain a consistent coding style by preferring designated initializers (which zero-initialize all the fields that are not specified) over memset() where possible, and make variable declarations local to inner scopes where applicable. One notable exception to this rule is in the ipu3 driver, where a memset() is needed as the structure is not a local variable but a function parameter provided by the caller. Not all fields of those structures can be initialized when declaring the variables, as the values for those fields are computed later in the code. Initialize the 'which' field in all cases, and other fields when the variable declaration is so close to the v4l2_subdev_call() call that it keeps all the context easily visible when reading the code, to avoid hindering readability. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Shuah Khan <skhan@linuxfoundation.org> # For vimc 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> # For drivers/staging/media/imx/ Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Diffstat (limited to 'drivers/media/platform/ti/omap3isp/ispvideo.c')
-rw-r--r--drivers/media/platform/ti/omap3isp/ispvideo.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/media/platform/ti/omap3isp/ispvideo.c b/drivers/media/platform/ti/omap3isp/ispvideo.c
index ddc7d08d4f96..daca689dc082 100644
--- a/drivers/media/platform/ti/omap3isp/ispvideo.c
+++ b/drivers/media/platform/ti/omap3isp/ispvideo.c
@@ -268,7 +268,9 @@ static int isp_video_get_graph_data(struct isp_video *video,
static int
__isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
{
- struct v4l2_subdev_format fmt;
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
struct v4l2_subdev *subdev;
u32 pad;
int ret;
@@ -278,7 +280,6 @@ __isp_video_get_format(struct isp_video *video, struct v4l2_format *format)
return -EINVAL;
fmt.pad = pad;
- fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
mutex_lock(&video->mutex);
ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
@@ -731,7 +732,9 @@ static int
isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
{
struct isp_video *video = video_drvdata(file);
- struct v4l2_subdev_format fmt;
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
struct v4l2_subdev *subdev;
u32 pad;
int ret;
@@ -746,7 +749,6 @@ isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
fmt.pad = pad;
- fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
if (ret)
return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
@@ -759,7 +761,9 @@ static int
isp_video_get_selection(struct file *file, void *fh, struct v4l2_selection *sel)
{
struct isp_video *video = video_drvdata(file);
- struct v4l2_subdev_format format;
+ struct v4l2_subdev_format format = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
struct v4l2_subdev *subdev;
struct v4l2_subdev_selection sdsel = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
@@ -799,7 +803,6 @@ isp_video_get_selection(struct file *file, void *fh, struct v4l2_selection *sel)
return ret;
format.pad = pad;
- format.which = V4L2_SUBDEV_FORMAT_ACTIVE;
ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format);
if (ret < 0)
return ret == -ENOIOCTLCMD ? -ENOTTY : ret;
@@ -957,7 +960,9 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
struct media_pad *source_pad;
struct media_entity *source = NULL;
struct media_entity *sink;
- struct v4l2_subdev_format fmt;
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
struct v4l2_ext_controls ctrls;
struct v4l2_ext_control ctrl;
unsigned int i;
@@ -993,7 +998,6 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
pipe->external = media_entity_to_v4l2_subdev(source);
fmt.pad = source_pad->index;
- fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
ret = v4l2_subdev_call(media_entity_to_v4l2_subdev(sink),
pad, get_fmt, NULL, &fmt);
if (unlikely(ret < 0)) {