From patchwork Sat May 11 10:10:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10939725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C97376 for ; Sat, 11 May 2019 10:10:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B1C11FF7E for ; Sat, 11 May 2019 10:10:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F69B2018E; Sat, 11 May 2019 10:10:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 441C61FF7E for ; Sat, 11 May 2019 10:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728584AbfEKKKl (ORCPT ); Sat, 11 May 2019 06:10:41 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:39777 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728537AbfEKKKk (ORCPT ); Sat, 11 May 2019 06:10:40 -0400 Received: by mail-lf1-f65.google.com with SMTP id f1so5827343lfl.6; Sat, 11 May 2019 03:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oSpctHaeZvdNFoGnQ3pujx7wuspbghI95adHykM4e7I=; b=eqze8Ep54tuWvlO6Nfxrc5QVi3tnVW8Mc3kXw+MR9Yv0xu6LKGw/oq0EXKm5pmcztD ppTU69OPc0sIIg5au2TZAwSwGs6YqTjj7eylGHaS+Gsxp0q+c+io9Li9cFENOh4gje9I g99ArRrRw/Q/jCok2wQDQTq1C1NpsWiUiKqJebJlnKXQd7V7qaLQL0G3Q++MnEDBQ0g/ dOzY51RBXPSK2n8A0rt1KC/KiH6Cs+Pu3ZXu/j7QOaoNP1nMMcYDBsrpfy1NymrmgSa+ s+u5x5Oa2EJpo34te249O0vvFm1rGvHT04zXQRe5xfvpH5VnFemZxAreYdWH4XQs5xj5 caUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oSpctHaeZvdNFoGnQ3pujx7wuspbghI95adHykM4e7I=; b=Tou3hvFJNCVwpv0X1a89m/jVlCOW1rLrNpvsdbDScWiIuH8DsiNSM2ysH0qXGfVuYp wBSy7GJ1CvFkLbxPkF7+jegSjGoRAfIwZxqYOeXmO28xOYuNlNr2mAZvDpIMawYhoB7U ElNE2yOtLwZR3dtg5kXT6/IWa/iRaZP9787ali/dJAP7It/y8JJHE9/eJEvYFNMi7n8d E7cl2suZhu03LBjUuMLIOWqF5+KNwrfq8Eo2edulNaj7noM1gju5XKT5eSH3JCQAG388 p8nl6aMIOavkd3/TwVGKLFtspGu//x4sxKDM1ctFKxBsjdaJIGoKzR+g5gAiDtPBDjxn 86YQ== X-Gm-Message-State: APjAAAVSEgtS+8fEwjswVwQiS0Mg62XAHWGvPtTUXcxU548ut/8oeNBX 8Lusg8sgXaf7mCInR/g/Fy/gOIGdbkw= X-Google-Smtp-Source: APXvYqxEtynsevCrK7THEfsKujdH0OZl+6C9yIk9GOr5lmIF7wRndj+CvuqPe3z6TAay/muVHwkU4A== X-Received: by 2002:a19:4a04:: with SMTP id x4mr8269188lfa.124.1557569436986; Sat, 11 May 2019 03:10:36 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id o124sm1443874lfe.92.2019.05.11.03.10.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 May 2019 03:10:36 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Hans Verkuil , Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH v4 1/2] media: v4l2-subdev: Verify arguments of v4l2_subdev_call() Date: Sat, 11 May 2019 12:10:30 +0200 Message-Id: <20190511101031.4777-2-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190511101031.4777-1-jmkrzyszt@gmail.com> References: <20190511101031.4777-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Correctness of format type (try or active) and pad number parameters passed to subdevice operation callbacks is now verified only for IOCTL calls. However, those callbacks are also used by drivers, e.g., V4L2 host interfaces. Since both subdev_do_ioctl() and drivers are using v4l2_subdev_call() macro while calling subdevice operations, move those parameter checks from subdev_do_ioctl() to v4l2_subdev_call() so we can avoid taking care of those checks inside drivers. Signed-off-by: Janusz Krzysztofik --- drivers/media/v4l2-core/v4l2-subdev.c | 222 +++++++++++++++----------- include/media/v4l2-subdev.h | 6 + 2 files changed, 139 insertions(+), 89 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d75815ab0d7b..cd50fcb86c47 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -120,56 +120,165 @@ static int subdev_close(struct file *file) return 0; } +static inline int check_which(__u32 which) +{ + return which != V4L2_SUBDEV_FORMAT_TRY && + which != V4L2_SUBDEV_FORMAT_ACTIVE ? -EINVAL : 0; +} + #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) +static inline int check_pad(struct v4l2_subdev *sd, __u32 pad) +{ + return pad >= sd->entity.num_pads ? -EINVAL : 0; +} +#else +#define check_pad(...) 0 +#endif + static int check_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *format) { - if (format->which != V4L2_SUBDEV_FORMAT_TRY && - format->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; + return check_which(format->which) ? : check_pad(sd, format->pad); +} - if (format->pad >= sd->entity.num_pads) - return -EINVAL; +static int check_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + return check_format(sd, format) ? : + sd->ops->pad->get_fmt(sd, cfg, format); +} - return 0; +static int check_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + return check_format(sd, format) ? : + sd->ops->pad->set_fmt(sd, cfg, format); } -static int check_crop(struct v4l2_subdev *sd, struct v4l2_subdev_crop *crop) +static int check_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code) { - if (crop->which != V4L2_SUBDEV_FORMAT_TRY && - crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; + return check_which(code->which) ? : check_pad(sd, code->pad) ? : + sd->ops->pad->enum_mbus_code(sd, cfg, code); +} - if (crop->pad >= sd->entity.num_pads) - return -EINVAL; +static int check_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse) +{ + return check_which(fse->which) ? : check_pad(sd, fse->pad) ? : + sd->ops->pad->enum_frame_size(sd, cfg, fse); +} - return 0; +static int check_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *fi) +{ + return check_pad(sd, fi->pad); +} + +static int check_g_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *fi) +{ + return check_frame_interval(sd, fi) ? : + sd->ops->video->g_frame_interval(sd, fi); +} + +static int check_s_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *fi) +{ + return check_frame_interval(sd, fi) ? : + sd->ops->video->s_frame_interval(sd, fi); +} + +static int check_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_interval_enum *fie) +{ + return check_which(fie->which) ? : check_pad(sd, fie->pad) ? : + sd->ops->pad->enum_frame_interval(sd, cfg, fie); } static int check_selection(struct v4l2_subdev *sd, struct v4l2_subdev_selection *sel) { - if (sel->which != V4L2_SUBDEV_FORMAT_TRY && - sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; + return check_which(sel->which) ? : check_pad(sd, sel->pad); +} - if (sel->pad >= sd->entity.num_pads) - return -EINVAL; +static int check_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + return check_selection(sd, sel) ? : + sd->ops->pad->get_selection(sd, cfg, sel); +} - return 0; +static int check_set_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + return check_selection(sd, sel) ? : + sd->ops->pad->set_selection(sd, cfg, sel); } static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) { - if (edid->pad >= sd->entity.num_pads) - return -EINVAL; - if (edid->blocks && edid->edid == NULL) return -EINVAL; - return 0; + return check_pad(sd, edid->pad); +} + +static int check_get_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) +{ + return check_edid(sd, edid) ? : sd->ops->pad->get_edid(sd, edid); } -#endif + +static int check_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) +{ + return check_edid(sd, edid) ? : sd->ops->pad->set_edid(sd, edid); +} + +static int check_dv_timings_cap(struct v4l2_subdev *sd, + struct v4l2_dv_timings_cap *cap) +{ + return check_pad(sd, cap->pad) ? : + sd->ops->pad->dv_timings_cap(sd, cap); +} + +static int check_enum_dv_timings(struct v4l2_subdev *sd, + struct v4l2_enum_dv_timings *dvt) +{ + return check_pad(sd, dvt->pad) ? : + sd->ops->pad->enum_dv_timings(sd, dvt); +} + +static const struct v4l2_subdev_pad_ops v4l2_subdev_pad_chk_args = { + .get_fmt = check_get_fmt, + .set_fmt = check_set_fmt, + .enum_mbus_code = check_enum_mbus_code, + .enum_frame_size = check_enum_frame_size, + .enum_frame_interval = check_enum_frame_interval, + .get_selection = check_get_selection, + .set_selection = check_set_selection, + .get_edid = check_get_edid, + .set_edid = check_set_edid, + .dv_timings_cap = check_dv_timings_cap, + .enum_dv_timings = check_enum_dv_timings, +}; + +static const struct v4l2_subdev_video_ops v4l2_subdev_video_chk_args = { + .g_frame_interval = check_g_frame_interval, + .s_frame_interval = check_s_frame_interval, +}; + +struct v4l2_subdev_ops v4l2_subdev_call_chk_args = { + .pad = &v4l2_subdev_pad_chk_args, + .video = &v4l2_subdev_video_chk_args, +}; +EXPORT_SYMBOL(v4l2_subdev_call_chk_args); static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) { @@ -292,10 +401,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_G_FMT: { struct v4l2_subdev_format *format = arg; - rval = check_format(sd, format); - if (rval) - return rval; - memset(format->reserved, 0, sizeof(format->reserved)); memset(format->format.reserved, 0, sizeof(format->format.reserved)); return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh->pad, format); @@ -304,10 +409,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_S_FMT: { struct v4l2_subdev_format *format = arg; - rval = check_format(sd, format); - if (rval) - return rval; - memset(format->reserved, 0, sizeof(format->reserved)); memset(format->format.reserved, 0, sizeof(format->format.reserved)); return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh->pad, format); @@ -317,10 +418,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) struct v4l2_subdev_crop *crop = arg; struct v4l2_subdev_selection sel; - rval = check_crop(sd, crop); - if (rval) - return rval; - memset(crop->reserved, 0, sizeof(crop->reserved)); memset(&sel, 0, sizeof(sel)); sel.which = crop->which; @@ -340,10 +437,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) struct v4l2_subdev_selection sel; memset(crop->reserved, 0, sizeof(crop->reserved)); - rval = check_crop(sd, crop); - if (rval) - return rval; - memset(&sel, 0, sizeof(sel)); sel.which = crop->which; sel.pad = crop->pad; @@ -361,13 +454,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_ENUM_MBUS_CODE: { struct v4l2_subdev_mbus_code_enum *code = arg; - if (code->which != V4L2_SUBDEV_FORMAT_TRY && - code->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - if (code->pad >= sd->entity.num_pads) - return -EINVAL; - memset(code->reserved, 0, sizeof(code->reserved)); return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh->pad, code); @@ -376,13 +462,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: { struct v4l2_subdev_frame_size_enum *fse = arg; - if (fse->which != V4L2_SUBDEV_FORMAT_TRY && - fse->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - if (fse->pad >= sd->entity.num_pads) - return -EINVAL; - memset(fse->reserved, 0, sizeof(fse->reserved)); return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh->pad, fse); @@ -391,9 +470,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_G_FRAME_INTERVAL: { struct v4l2_subdev_frame_interval *fi = arg; - if (fi->pad >= sd->entity.num_pads) - return -EINVAL; - memset(fi->reserved, 0, sizeof(fi->reserved)); return v4l2_subdev_call(sd, video, g_frame_interval, arg); } @@ -401,9 +477,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_S_FRAME_INTERVAL: { struct v4l2_subdev_frame_interval *fi = arg; - if (fi->pad >= sd->entity.num_pads) - return -EINVAL; - memset(fi->reserved, 0, sizeof(fi->reserved)); return v4l2_subdev_call(sd, video, s_frame_interval, arg); } @@ -411,13 +484,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: { struct v4l2_subdev_frame_interval_enum *fie = arg; - if (fie->which != V4L2_SUBDEV_FORMAT_TRY && - fie->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - if (fie->pad >= sd->entity.num_pads) - return -EINVAL; - memset(fie->reserved, 0, sizeof(fie->reserved)); return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh->pad, fie); @@ -426,10 +492,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_G_SELECTION: { struct v4l2_subdev_selection *sel = arg; - rval = check_selection(sd, sel); - if (rval) - return rval; - memset(sel->reserved, 0, sizeof(sel->reserved)); return v4l2_subdev_call( sd, pad, get_selection, subdev_fh->pad, sel); @@ -438,10 +500,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_SUBDEV_S_SELECTION: { struct v4l2_subdev_selection *sel = arg; - rval = check_selection(sd, sel); - if (rval) - return rval; - memset(sel->reserved, 0, sizeof(sel->reserved)); return v4l2_subdev_call( sd, pad, set_selection, subdev_fh->pad, sel); @@ -450,38 +508,24 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) case VIDIOC_G_EDID: { struct v4l2_subdev_edid *edid = arg; - rval = check_edid(sd, edid); - if (rval) - return rval; - return v4l2_subdev_call(sd, pad, get_edid, edid); } case VIDIOC_S_EDID: { struct v4l2_subdev_edid *edid = arg; - rval = check_edid(sd, edid); - if (rval) - return rval; - return v4l2_subdev_call(sd, pad, set_edid, edid); } case VIDIOC_SUBDEV_DV_TIMINGS_CAP: { struct v4l2_dv_timings_cap *cap = arg; - if (cap->pad >= sd->entity.num_pads) - return -EINVAL; - return v4l2_subdev_call(sd, pad, dv_timings_cap, cap); } case VIDIOC_SUBDEV_ENUM_DV_TIMINGS: { struct v4l2_enum_dv_timings *dvt = arg; - if (dvt->pad >= sd->entity.num_pads) - return -EINVAL; - return v4l2_subdev_call(sd, pad, enum_dv_timings, dvt); } diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a7fa5b80915a..900f265fd950 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1091,6 +1091,8 @@ void v4l2_subdev_free_pad_config(struct v4l2_subdev_pad_config *cfg); void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops); +extern struct v4l2_subdev_ops v4l2_subdev_call_chk_args; + /** * v4l2_subdev_call - call an operation of a v4l2_subdev. * @@ -1112,6 +1114,10 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, __result = -ENODEV; \ else if (!(__sd->ops->o && __sd->ops->o->f)) \ __result = -ENOIOCTLCMD; \ + else if (v4l2_subdev_call_chk_args.o && \ + v4l2_subdev_call_chk_args.o->f) \ + __result = v4l2_subdev_call_chk_args.o->f( \ + __sd, ##args); \ else \ __result = __sd->ops->o->f(__sd, ##args); \ __result; \ From patchwork Sat May 11 10:10:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10939723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23B0B112C for ; Sat, 11 May 2019 10:10:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 101B81FF7E for ; Sat, 11 May 2019 10:10:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1A6C2018E; Sat, 11 May 2019 10:10:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE5DC1FF7E for ; Sat, 11 May 2019 10:10:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728599AbfEKKKo (ORCPT ); Sat, 11 May 2019 06:10:44 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42797 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726231AbfEKKKl (ORCPT ); Sat, 11 May 2019 06:10:41 -0400 Received: by mail-lf1-f65.google.com with SMTP id w23so5814922lfc.9; Sat, 11 May 2019 03:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VNziprtODNmMoGsygckPqFLlWbtsE4xrmyr6LqQcJPU=; b=T31OFSZEB0PMhRV9D9kA0NgN8P5U3Y8KnGVmYQBnM2NPWv/aIQqN3uBtgeFkem7G78 Q+eFPkAz5qhg9qvpO3LzK09sfpQLJKDVdKB9JES5EZMkUwxsNFLORsjFL+f+nkkSazhV kM8tNpeVxlAWxcafT4Vxwlh3NdLg+NUsnLxy6FghBn7W3QLig4d9sGLKUDx+LCkI67iP hJ881HMgoLPKDXxDgixGuOQM1IF8+07dWZKuDH7q9B6vq+qz5RzmVEkQ8G/fsQj4sjLH sAz0vaxL3a1kVmUba8pKcUQKXU55Fuhi1zGr9byIA2uv+0k4grL5+L8GZ+nKB9nr6lMM FiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VNziprtODNmMoGsygckPqFLlWbtsE4xrmyr6LqQcJPU=; b=KlYPcbLXkgrceCjpniVEk1IUexhuo89gh4D6GghUr8HqKoEigHbZ4fW2FREdaoNYdB kMt2WjE1iApWoThHVYP6Uj5fOH5Onqw6IIyJvFtT6dfYHgH4xJzgGOQC/kLJUeUJZZid vMk5bIevEQQzZ4mW46S1ju2maCxzTYYSsXyxBXn/2C6LCGtiP5PvqymxO4WafHJDiGPn zSRhaWij9AKuPX9n+sCl7lof+Lb/pe3aZhKqjB3rLiBP/KRUmraQdV7IRefm4xQ+/PiL CJFu1A+MBQTAkLGCk3VJSYC3UVf3mlwIKKJqCJwhZjs4m3HQtVJuIAP45D949oy/W1vg fKiw== X-Gm-Message-State: APjAAAVhwm1RvCd43h45Y8GWB8yTcB7UJTUhhvAmh9UtwAs6q1PqrmKz qLrrg0fu/dVIrXhA2JKbD8M= X-Google-Smtp-Source: APXvYqxsOdB2GNH5WR35dkuJsMwkCFIGpdrKb2gViuEijiUhHC7Nl7B05EOnMOYH46+uULp0wRzs7w== X-Received: by 2002:a19:9c8f:: with SMTP id f137mr8452860lfe.94.1557569438251; Sat, 11 May 2019 03:10:38 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id o124sm1443874lfe.92.2019.05.11.03.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 May 2019 03:10:37 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Hans Verkuil , Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH v4 2/2] media: v4l2-subdev: Verify pad config argument Date: Sat, 11 May 2019 12:10:31 +0200 Message-Id: <20190511101031.4777-3-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190511101031.4777-1-jmkrzyszt@gmail.com> References: <20190511101031.4777-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extend parameter checks performed by v4l2_subdev_call() with a check for a non-NULL pad config pointer if V4L2_SUBDEV_FORMAT_TRY format type is requested so drivers don't need to care. Signed-off-by: Janusz Krzysztofik --- drivers/media/v4l2-core/v4l2-subdev.c | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index cd50fcb86c47..4540d8abff5f 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -126,6 +126,11 @@ static inline int check_which(__u32 which) which != V4L2_SUBDEV_FORMAT_ACTIVE ? -EINVAL : 0; } +static inline int check_cfg(__u32 which, struct v4l2_subdev_pad_config *cfg) +{ + return which == V4L2_SUBDEV_FORMAT_TRY && !cfg ? -EINVAL : 0; +} + #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) static inline int check_pad(struct v4l2_subdev *sd, __u32 pad) { @@ -136,16 +141,18 @@ static inline int check_pad(struct v4l2_subdev *sd, __u32 pad) #endif static int check_format(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) { - return check_which(format->which) ? : check_pad(sd, format->pad); + return check_which(format->which) ? : + check_cfg(format->which, cfg) ? : check_pad(sd, format->pad); } static int check_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) { - return check_format(sd, format) ? : + return check_format(sd, cfg, format) ? : sd->ops->pad->get_fmt(sd, cfg, format); } @@ -153,7 +160,7 @@ static int check_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) { - return check_format(sd, format) ? : + return check_format(sd, cfg, format) ? : sd->ops->pad->set_fmt(sd, cfg, format); } @@ -161,7 +168,8 @@ static int check_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { - return check_which(code->which) ? : check_pad(sd, code->pad) ? : + return check_which(code->which) ? : check_cfg(code->which, cfg) ? : + check_pad(sd, code->pad) ? : sd->ops->pad->enum_mbus_code(sd, cfg, code); } @@ -169,7 +177,8 @@ static int check_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { - return check_which(fse->which) ? : check_pad(sd, fse->pad) ? : + return check_which(fse->which) ? : check_cfg(fse->which, cfg) ? : + check_pad(sd, fse->pad) ? : sd->ops->pad->enum_frame_size(sd, cfg, fse); } @@ -197,21 +206,24 @@ static int check_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) { - return check_which(fie->which) ? : check_pad(sd, fie->pad) ? : + return check_which(fie->which) ? : check_cfg(fie->which, cfg) ? : + check_pad(sd, fie->pad) ? : sd->ops->pad->enum_frame_interval(sd, cfg, fie); } static int check_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { - return check_which(sel->which) ? : check_pad(sd, sel->pad); + return check_which(sel->which) ? : check_cfg(sel->which, cfg) ? : + check_pad(sd, sel->pad); } static int check_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { - return check_selection(sd, sel) ? : + return check_selection(sd, cfg, sel) ? : sd->ops->pad->get_selection(sd, cfg, sel); } @@ -219,7 +231,7 @@ static int check_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { - return check_selection(sd, sel) ? : + return check_selection(sd, cfg, sel) ? : sd->ops->pad->set_selection(sd, cfg, sel); }