From patchwork Sun May 12 20:15:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10940155 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 20085924 for ; Sun, 12 May 2019 20:16:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1157320587 for ; Sun, 12 May 2019 20:16:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05365268AE; Sun, 12 May 2019 20:16:36 +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 1976320587 for ; Sun, 12 May 2019 20:16:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbfELUQM (ORCPT ); Sun, 12 May 2019 16:16:12 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:44829 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbfELUQL (ORCPT ); Sun, 12 May 2019 16:16:11 -0400 Received: by mail-lf1-f66.google.com with SMTP id n134so7464098lfn.11; Sun, 12 May 2019 13:16:08 -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=danRkZ9JKwXCg9PoO9hbEsKI44VYWoTAG9NK0/Sog+0=; b=vUALBzsjsntG1a5LzzWv+OJ0mIEP6tEDyFPzJ8noK77LbPra1FXsG2lGuzG1oDJ1hm Op0B+yHYZQeVEF6izQuuNhMvxJ24fuf/OQN2AfzITrplejoj3h52nX/mijqyaCz/JL2b N9V5OGHEjDxs8u6fO08ZE2Ab8uiQhQlWUS2wtfSNIkyXvIFxlDR9Vp8+daobZGce58dJ hHTvdpocAkhZx65NR0B1WgwA+fw8+I3ic57vJNQ15BMUcr4tRvouharBwJgIj0Y3hElq fj3xROptCiF9y1gOC7+0i/XJCVTomsUAkwfMcM0WBQ/EeIXk4bt5e6YyeafBvmlL+rCp dfrg== 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=danRkZ9JKwXCg9PoO9hbEsKI44VYWoTAG9NK0/Sog+0=; b=pcdDZoOwg3pHtbmogM16tIP2IFuzSYrPCFGTHfS+dnjjsGXlslJZ0iyV1uTL+V8y80 UR6f4Q9iIwvsMpwAnvKhsSgn1c24zIU8CpE8sz+v3AWW0t0LeNFrUKKJfbKRLv2GeE6u 6bL4nbqY0fsYheb1UkswpuiXmiHotUyqRQyKWhDPoL0owHB6I38SckWwaNNly3bBC4gS IkFcylIgYhycvodCU+hgSuH30qeBNuRbHB8o66EGQqCiZFwc92S7zl9nFdAvpLvikD+n b9fUgfLTaplt3cuEW50Vxg5JKZU/h/Y9gkgqeLjawkZXuvSyuQVnrCVxlOXgP3N83kan SP/g== X-Gm-Message-State: APjAAAVmam+O5ejTH52rrx/WqRAnq5M7Z/q9toHZYlZJstRmvSshVdDu vsAsKktTrDK9bqFaeiSWgfE= X-Google-Smtp-Source: APXvYqxioIKCAjoP3tt/AmaaeFEBUsmKUPMvmEa0JjIuFRrhekLHhobvcgqlpa3eQJsI1htsnW97sA== X-Received: by 2002:ac2:514b:: with SMTP id q11mr11558243lfd.114.1557692168008; Sun, 12 May 2019 13:16:08 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id w20sm2360533ljd.39.2019.05.12.13.16.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 13:16:07 -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 v5 1/4] media: v4l2-subdev: Verify arguments in v4l2_subdev_call() Date: Sun, 12 May 2019 22:15:48 +0200 Message-Id: <20190512201551.18724-2-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190512201551.18724-1-jmkrzyszt@gmail.com> References: <20190512201551.18724-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 ID 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. Define a wrapper function for each operation callback in scope, then gather those wrappers in a static v4l2_subdev_ops structure so the v4l2_subdev_call() macro can find them easy if provided. Move reusable code to helpers. Signed-off-by: Janusz Krzysztofik --- drivers/media/v4l2-core/v4l2-subdev.c | 227 ++++++++++++++++---------- include/media/v4l2-subdev.h | 6 + 2 files changed, 143 insertions(+), 90 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d75815ab0d7b..890916674d42 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -120,56 +120,168 @@ static int subdev_close(struct file *file) return 0; } -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) -static int check_format(struct v4l2_subdev *sd, - struct v4l2_subdev_format *format) +static int check_which(__u32 which) { - if (format->which != V4L2_SUBDEV_FORMAT_TRY && - format->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - if (format->pad >= sd->entity.num_pads) + if (which != V4L2_SUBDEV_FORMAT_TRY && + which != V4L2_SUBDEV_FORMAT_ACTIVE) return -EINVAL; return 0; } -static int check_crop(struct v4l2_subdev *sd, struct v4l2_subdev_crop *crop) +static int check_pad(struct v4l2_subdev *sd, __u32 pad) { - if (crop->which != V4L2_SUBDEV_FORMAT_TRY && - crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) +#if defined(CONFIG_MEDIA_CONTROLLER) + if (sd->entity.num_pads && pad >= sd->entity.num_pads) return -EINVAL; +#endif + return 0; +} - if (crop->pad >= sd->entity.num_pads) - return -EINVAL; +static int check_format(struct v4l2_subdev *sd, + struct v4l2_subdev_format *format) +{ + return check_which(format->which) ? : check_pad(sd, format->pad); +} - return 0; +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); +} + +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_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) ? : + sd->ops->pad->enum_mbus_code(sd, cfg, code); +} + +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); +} + +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); } -#endif + +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); +} + +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 +404,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 +412,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 +421,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 +440,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 +457,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 +465,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 +473,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 +480,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 +487,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 +495,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 +503,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 +511,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 Sun May 12 20:15:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10940151 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 D4061912 for ; Sun, 12 May 2019 20:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C294F20587 for ; Sun, 12 May 2019 20:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4DDD268AE; Sun, 12 May 2019 20:16:27 +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 5F2AB20587 for ; Sun, 12 May 2019 20:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727118AbfELUQM (ORCPT ); Sun, 12 May 2019 16:16:12 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:38370 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726967AbfELUQL (ORCPT ); Sun, 12 May 2019 16:16:11 -0400 Received: by mail-lj1-f193.google.com with SMTP id 14so9123196ljj.5; Sun, 12 May 2019 13:16:09 -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=EaY1su4hEWKGEwfPVblCSADrkO2FOUhq1ciLnu8ghzI=; b=PrY1Wzjp46HKoTP4coQqHQyMrf/c6/KedYI4xU1E+ynvC7kwUW+7tlOxZcji2wFHao +XUru6DIMTohHTaanpX0foJjCacrOAbUQzbA328kzPa0yblP6KNYFul7lZA+SSUCzyEd FkbqC+PXTLR9bK1+plFDEBbjSDVwBsM4Ai0rVrQ7NxDPTrXEDTR00bh1XV9vervXUp/Y 2TI1NiXuaqSyaZbD+i1+Bob5T0ZkM6/dLUudpGKfbN98MHQvRgtTPAf8he7t6X1mR7jN GkFCB7NVtlaI7wLghE5e7D0PY3InR8WFE+W6Rm97SRjuLueBkkOoe9ajNVMUo2j21XAE wIFw== 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=EaY1su4hEWKGEwfPVblCSADrkO2FOUhq1ciLnu8ghzI=; b=HlYKSV9j/cwzek65HbFdQNTzYQlByLjel79RtLwkSKhic35XPmbXxYQO8l2EW7FKSw gLRNkRpFEnP0BfaMgXPV5cBIHeWCpdQCcXmpERYFbo0rHI/YY0WuyhKVJwnzRvFop3ml 8Q6pH0sdi2mwEbW5iKi7ap/k3aDA3uRaj7dzvVUSMaP1y9nWFa/a8KGhwgMaXtbUJtxA /bCH/uEkAHGwDJniTibHJkeh5febFe16kEm9lfxxb7LxX5Ulx3QcuU6NIE1rScKIvg3U 6C6wDAutaLIqx+2BvVWeP5SmJSguND1xW3VIXxRZrmw/kgGz0UYi9ph8SanTuvZAaFg4 x7eA== X-Gm-Message-State: APjAAAUudlOI5aFsh7C8by+NvX5TlQgoALexOFci0PEpKkFyGZ3vjb3o tZjWXwGqf6EUUHRMHEuDSyg= X-Google-Smtp-Source: APXvYqxuDS8jazRUOIjZxSKmwWmNMREJC4bx6CT8BNWtSKmQoF4sRSlLcCg6EEMMEk4ub6QxdSA7Yg== X-Received: by 2002:a2e:74f:: with SMTP id i15mr11424120ljd.156.1557692169180; Sun, 12 May 2019 13:16:09 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id w20sm2360533ljd.39.2019.05.12.13.16.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 13:16:08 -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 v5 2/4] media: v4l2-subdev: WARN_ON invalid v4l2_subdev_call() arguments Date: Sun, 12 May 2019 22:15:49 +0200 Message-Id: <20190512201551.18724-3-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190512201551.18724-1-jmkrzyszt@gmail.com> References: <20190512201551.18724-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 Invalid arguments passed to v4l2_subdev_call generally mean bugs. Be noisy if that happens. Signed-off-by: Janusz Krzysztofik --- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 890916674d42..5f2264575cd7 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -122,8 +122,8 @@ static int subdev_close(struct file *file) static int check_which(__u32 which) { - if (which != V4L2_SUBDEV_FORMAT_TRY && - which != V4L2_SUBDEV_FORMAT_ACTIVE) + if (WARN_ON(which != V4L2_SUBDEV_FORMAT_TRY && + which != V4L2_SUBDEV_FORMAT_ACTIVE)) return -EINVAL; return 0; @@ -132,7 +132,7 @@ static int check_which(__u32 which) static int check_pad(struct v4l2_subdev *sd, __u32 pad) { #if defined(CONFIG_MEDIA_CONTROLLER) - if (sd->entity.num_pads && pad >= sd->entity.num_pads) + if (WARN_ON(sd->entity.num_pads && pad >= sd->entity.num_pads)) return -EINVAL; #endif return 0; @@ -228,7 +228,7 @@ static int check_set_selection(struct v4l2_subdev *sd, static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) { - if (edid->blocks && edid->edid == NULL) + if (WARN_ON(edid->blocks && edid->edid == NULL)) return -EINVAL; return check_pad(sd, edid->pad); From patchwork Sun May 12 20:15:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10940153 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 2A9AA924 for ; Sun, 12 May 2019 20:16:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C97520587 for ; Sun, 12 May 2019 20:16:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10B33268AE; Sun, 12 May 2019 20:16:33 +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 97D8020587 for ; Sun, 12 May 2019 20:16:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727162AbfELUQ1 (ORCPT ); Sun, 12 May 2019 16:16:27 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40283 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727095AbfELUQM (ORCPT ); Sun, 12 May 2019 16:16:12 -0400 Received: by mail-lj1-f193.google.com with SMTP id d15so9121061ljc.7; Sun, 12 May 2019 13:16:11 -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=54Cg2KVLeyPm5R5v7PD/4q6SqBNJQ7DqejFPZlBrBC4=; b=HWOb2t35yhJBVcUxfI3fKcnBNckQur2cBj55IKa3BrM2roHViMTf8zB+eqJ86Qi7ph Uh0L1eueQEM/dda78pNMBteXiO5jy2NPXhj4Oil26qq6Reh9pAU2HHlC2FWUg/ojMmiJ KUimp5kcFQIjVDxJcLEC4vm43vDBZ0p5++p4mJfv9hLtgHUSpnZ4gio7GXYqwwK71eam ICQl/0XQCgDb+lD2BxSU2RTSuKpYM6IfUpBqKS5PZlK1kQivVLxx852CBx2k3MubcdhC 0VK23wroRFWk/L0GucCHUvLYWcxdn8kmeSUaTXNKdZVT07fe32GA/2EeQ/civMQLj4MD w88g== 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=54Cg2KVLeyPm5R5v7PD/4q6SqBNJQ7DqejFPZlBrBC4=; b=t5LCDP3Nqzaj1h99FjAqoIdZJvG+b5ZBQ82loJumReZMdFxSa8T0Mb3/Iyh9TkypfX KtxaO9admFLRWh50OtMQgiDOg1VKbZQYtUcrapfc40hA2sQYno19Cr6bGIeojfIitfPO gWcOV5dTG00LrXjY1iH174u9yyBSphidSbwb/iAaK8Gi0CdfG/Qyrh4p+a5VqZwn2cTv yKiaRhHH8D6ceZlzPePpvKwWwLrAvwjrCzU1k/N13Zb5dG2KzKuC+nbF6JKs9ZGR/Nxx jQN4JNMIgic13ism5l7EAzzm4R+4GaWac0Aqd4J4yH0luNVoCezBp7ZUs7VbLIGOHfYZ EkkA== X-Gm-Message-State: APjAAAW2cQeZcHG7bfkopBll0Dne9iShRKTEXNx8aIan1VSM6G0gEoe9 LzqNjowL/8gzF/7GrS3dxl4= X-Google-Smtp-Source: APXvYqxIgdt4t13bhYmF48J/CcJj6S2R2Pjb/30njayHKuirfp7Ug+x3xXxiciIH4h42cM36xbfuLg== X-Received: by 2002:a2e:9d12:: with SMTP id t18mr11852434lji.163.1557692170428; Sun, 12 May 2019 13:16:10 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id w20sm2360533ljd.39.2019.05.12.13.16.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 13:16:09 -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 v5 3/4] media: v4l2-subdev: Verify v4l2_subdev_call() pointer arguments Date: Sun, 12 May 2019 22:15:50 +0200 Message-Id: <20190512201551.18724-4-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190512201551.18724-1-jmkrzyszt@gmail.com> References: <20190512201551.18724-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 Parameters passed to check helpers are now obtained by dereferencing unverified pointer arguments. Check validity of those pointers first. Signed-off-by: Janusz Krzysztofik --- drivers/media/v4l2-core/v4l2-subdev.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 5f2264575cd7..3fc07af26c5b 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -141,6 +141,9 @@ static int check_pad(struct v4l2_subdev *sd, __u32 pad) static int check_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *format) { + if (WARN_ON(!format)) + return -EINVAL; + return check_which(format->which) ? : check_pad(sd, format->pad); } @@ -164,6 +167,9 @@ static int check_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { + if (WARN_ON(!code)) + return -EINVAL; + return check_which(code->which) ? : check_pad(sd, code->pad) ? : sd->ops->pad->enum_mbus_code(sd, cfg, code); } @@ -172,6 +178,9 @@ static int check_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { + if (WARN_ON(!fse)) + return -EINVAL; + return check_which(fse->which) ? : check_pad(sd, fse->pad) ? : sd->ops->pad->enum_frame_size(sd, cfg, fse); } @@ -179,6 +188,9 @@ static int check_enum_frame_size(struct v4l2_subdev *sd, static int check_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_frame_interval *fi) { + if (WARN_ON(!fi)) + return -EINVAL; + return check_pad(sd, fi->pad); } @@ -200,6 +212,9 @@ static int check_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) { + if (WARN_ON(!fie)) + return -EINVAL; + return check_which(fie->which) ? : check_pad(sd, fie->pad) ? : sd->ops->pad->enum_frame_interval(sd, cfg, fie); } @@ -207,6 +222,9 @@ static int check_enum_frame_interval(struct v4l2_subdev *sd, static int check_selection(struct v4l2_subdev *sd, struct v4l2_subdev_selection *sel) { + if (WARN_ON(!sel)) + return -EINVAL; + return check_which(sel->which) ? : check_pad(sd, sel->pad); } @@ -228,6 +246,9 @@ static int check_set_selection(struct v4l2_subdev *sd, static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) { + if (WARN_ON(!edid)) + return -EINVAL; + if (WARN_ON(edid->blocks && edid->edid == NULL)) return -EINVAL; @@ -247,6 +268,9 @@ static int check_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) static int check_dv_timings_cap(struct v4l2_subdev *sd, struct v4l2_dv_timings_cap *cap) { + if (WARN_ON(!cap)) + return -EINVAL; + return check_pad(sd, cap->pad) ? : sd->ops->pad->dv_timings_cap(sd, cap); } @@ -254,6 +278,9 @@ static int check_dv_timings_cap(struct v4l2_subdev *sd, static int check_enum_dv_timings(struct v4l2_subdev *sd, struct v4l2_enum_dv_timings *dvt) { + if (WARN_ON(!dvt)) + return -EINVAL; + return check_pad(sd, dvt->pad) ? : sd->ops->pad->enum_dv_timings(sd, dvt); } From patchwork Sun May 12 20:15:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10940149 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 153EA924 for ; Sun, 12 May 2019 20:16:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0396C20587 for ; Sun, 12 May 2019 20:16:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E674C268AE; Sun, 12 May 2019 20:16:23 +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 6885920587 for ; Sun, 12 May 2019 20:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbfELUQR (ORCPT ); Sun, 12 May 2019 16:16:17 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:33922 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbfELUQN (ORCPT ); Sun, 12 May 2019 16:16:13 -0400 Received: by mail-lf1-f68.google.com with SMTP id v18so7502170lfi.1; Sun, 12 May 2019 13:16:12 -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=TtItGs0FkM3NnCnDWxQXotXpTul745ITl9R2PbQtgGs=; b=hY+EwV0uZ3bHDdlvNexq9jALPBLzyYYhPWtScl0RqT+Kxrn4WN7X4Uk5g+6KexKaXK X/HlmLwMNmTzsBu+KuABVQ0NqPPOXdjsxdayV1UCRHuQjB+84iThseDnyupHC43ydIsh qpJFlzyvl4glJc4Vope2x4ZJg6v/o8PFCMEP6/wBUytAxSo+fjgRfDf27Tw5XocjVEvl JDyLiSrzklrcdI9ExPUgnbr3MSDKcRUImD0Huyv8EXz9aix+U5KnQ/oc4p++9+GFuApU 8ILn1ySbYw5SV8XRMO7t1j9uT1Tl36eg9jGlhCSMwhXAp7lGHKWCXbFaq0UyB2AEX7VJ n4pg== 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=TtItGs0FkM3NnCnDWxQXotXpTul745ITl9R2PbQtgGs=; b=m9l7Z+gQwePj6Tjsk1P0oaJgX7deiM+Iai6v35JCtaY0YGjlO2JAjHI3Z8nNyDutNz Sqh6AF936/FtMc5/QbdSX+CRpRxWr3Ftg4SwvpI1+/y+Ug8dmraPLmrm9dv8n3sgGDBX puB2U5GOwIJx9q6N2R3mkFZeXuzHnhMtznhAy1oS9D7sz9PR7nyjPY67xsssa03pMGmu EE6wm3LA7zxxHvCvHP1CsO5dkBdxZ8Hcoe99m7sGvcoxVzbI8NzbelK+OWNOcUqaLSeX DCYEPDJozrlaayr0Ccm0yIhrgvrMoQVq7H0hRuHeFdGDEbnWUW2wFFqjxIZLkAaMY5Wy rZjA== X-Gm-Message-State: APjAAAVlwHX7UvKNo0iEr12yWkT+ezbbVELi9HSVa2lOx1iikafnKRyQ omy6TbNJilt/L109VidrYjQ= X-Google-Smtp-Source: APXvYqwR2ALS3zet1OsLsKMHvSUdN0Qlhth88/6Q+VTp82e83lzlk+FPwX3cb042SxwknKX28TrERg== X-Received: by 2002:a19:c394:: with SMTP id t142mr7034168lff.102.1557692171588; Sun, 12 May 2019 13:16:11 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id w20sm2360533ljd.39.2019.05.12.13.16.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 13:16:11 -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 v5 4/4] media: v4l2-subdev: Verify v4l2_subdev_call() pad config argument Date: Sun, 12 May 2019 22:15:51 +0200 Message-Id: <20190512201551.18724-5-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190512201551.18724-1-jmkrzyszt@gmail.com> References: <20190512201551.18724-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 | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 3fc07af26c5b..fc8c308fb060 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -138,20 +138,30 @@ static int check_pad(struct v4l2_subdev *sd, __u32 pad) return 0; } +static int check_cfg(__u32 which, struct v4l2_subdev_pad_config *cfg) +{ + if (WARN_ON(which == V4L2_SUBDEV_FORMAT_TRY && !cfg)) + return -EINVAL; + + return 0; +} + static int check_format(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *format) { if (WARN_ON(!format)) return -EINVAL; - return check_which(format->which) ? : check_pad(sd, format->pad); + return check_which(format->which) ? : check_pad(sd, format->pad) ? : + check_cfg(format->which, cfg); } 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); } @@ -159,7 +169,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); } @@ -171,6 +181,7 @@ static int check_enum_mbus_code(struct v4l2_subdev *sd, return -EINVAL; return check_which(code->which) ? : check_pad(sd, code->pad) ? : + check_cfg(code->which, cfg) ? : sd->ops->pad->enum_mbus_code(sd, cfg, code); } @@ -182,6 +193,7 @@ static int check_enum_frame_size(struct v4l2_subdev *sd, return -EINVAL; return check_which(fse->which) ? : check_pad(sd, fse->pad) ? : + check_cfg(fse->which, cfg) ? : sd->ops->pad->enum_frame_size(sd, cfg, fse); } @@ -216,23 +228,26 @@ static int check_enum_frame_interval(struct v4l2_subdev *sd, return -EINVAL; return check_which(fie->which) ? : check_pad(sd, fie->pad) ? : + check_cfg(fie->which, cfg) ? : 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) { if (WARN_ON(!sel)) return -EINVAL; - return check_which(sel->which) ? : check_pad(sd, sel->pad); + return check_which(sel->which) ? : check_pad(sd, sel->pad) ? : + check_cfg(sel->which, cfg); } 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); } @@ -240,7 +255,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); }