Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2270071pxm; Fri, 4 Mar 2022 12:46:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+5ELO3Y31hcTBfyGjthd6c5eyVUjR4w0vBAQ4bNVWXhbeR6LGDgyPTWthwn+WQkEzezNx X-Received: by 2002:a17:90a:c6:b0:1bc:c0be:4696 with SMTP id v6-20020a17090a00c600b001bcc0be4696mr12574203pjd.7.1646426796601; Fri, 04 Mar 2022 12:46:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426796; cv=none; d=google.com; s=arc-20160816; b=fNunby9n+I/qBGdyh+G6Vo1SD0+RsXU95bRCCdVtbJhKvUgETy8F1iDZVlXTgKiGqf ZV3PBaF1UHWKokYIkIOjjD9EnWM9KWFgYQn9SmQxj8c5hwAIkyLXE2IXT/xHrZ0RM7Py u2odGb2d7rvVNcraVbOznNInI1HZ4fBnWLFAydQpcktRLwV69hKbgsT1TVtJOY6C8oOa z79IVoAyYDGzIXmlu02kK+uLMY9lUDB8xJ3ln+5iYyHrPVflr3pHC287GwNa3DRZlNbg ouXxyvT4W2uMxY53Yi0pdGMwVnjwj6gyD4/b+D8XiYDowlnYjGLJguF8WaukPmNHRnmP k0FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ly9z43Cu3VJY1zy0oQ5mLBzOCKZwS22eebd5vOSxCMQ=; b=gHtpk9kRtZvL3hQ0wQVq0EqYGFkkgUShb9Mq2OAZfrQr1r5JmuqRrExdf12xWJfIme DUZUQ1S8eCtbHOUrmiKUBDmqDIXqrmHU7NowpIbYJw+Yxch/Ja6YXyty8XDJgjCk64wp lmiFPgOgwJ7rAWPNuImrCQRf/8ckj0692io4Dk94WQXg9Kmr1p+dgbv0a7h95Vtk9aXx 3RFdABjim9QS3uYQ9Q66lnkw2+FRoDDbwWFHb8E4AybdDrxGk3dJMzKrNvCBRQTOnMYc HYVOjorLsGGEo9M0UE3RTVpZ4dwgEzZ/wxp1ThmqOpbbVBwBGgAByDIWuBcWo19D1Td+ 1hCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=JPF+PX5x; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i2-20020a17090a65c200b001bd14e0307asi443782pjs.82.2022.03.04.12.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:46:36 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=JPF+PX5x; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D16E30A15B; Fri, 4 Mar 2022 11:47:28 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239664AbiCDMKj (ORCPT + 99 others); Fri, 4 Mar 2022 07:10:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbiCDMKi (ORCPT ); Fri, 4 Mar 2022 07:10:38 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 770C11A6F83; Fri, 4 Mar 2022 04:09:50 -0800 (PST) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DA4DF51C; Fri, 4 Mar 2022 13:09:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1646395789; bh=V3tPVMEO+Jq2klZv9qatnhwYwoLpYgaa6zzWUUOn5XE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JPF+PX5xMyBl+3ZOhN5TT74AfjoyDD68PReLFygt7fsddbZoCvL3QVsR2BtLo3wYV Lr3GQhO0VCxU0UPqqJrQiRB3GlAr3MF5FiJv1FJPTNq5DjN/piozKnoV0gt4gsZk4L NE+J29i+BvoKsXE3AN8Rsf66oCCo7uubKf7C8E2o= Date: Fri, 4 Mar 2022 14:09:36 +0200 From: Laurent Pinchart To: xkernel.wang@foxmail.com Cc: sakari.ailus@iki.fi, mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: omap3isp: check the return of __ccp2_get_format() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Xiaoke, Thank you for the patch. On Fri, Mar 04, 2022 at 07:48:18PM +0800, xkernel.wang@foxmail.com wrote: > From: Xiaoke Wang > > __ccp2_get_format() returns format structure or NULL on error. > So it is better to check the return value of it to prevent potential > wrong memory access. The function can actually never return NULL if it's called with a valid pad number, which should always be the case as far as I can tell (since commit a8fa55078a778). This patch is thus not needed. > Signed-off-by: Xiaoke Wang > --- > drivers/media/platform/omap3isp/ispccp2.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c > index acb58b6..81881b1 100644 > --- a/drivers/media/platform/omap3isp/ispccp2.c > +++ b/drivers/media/platform/omap3isp/ispccp2.c > @@ -675,8 +675,10 @@ static void ccp2_try_format(struct isp_ccp2_device *ccp2, > */ > format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SINK, > which); > - memcpy(fmt, format, sizeof(*fmt)); > - fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; > + if (format != NULL) { > + memcpy(fmt, format, sizeof(*fmt)); > + fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; > + } > break; > } > > @@ -709,6 +711,9 @@ static int ccp2_enum_mbus_code(struct v4l2_subdev *sd, > > format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SINK, > code->which); > + if (format == NULL) > + return -EINVAL; > + > code->code = format->code; > } > > @@ -792,6 +797,9 @@ static int ccp2_set_format(struct v4l2_subdev *sd, > if (fmt->pad == CCP2_PAD_SINK) { > format = __ccp2_get_format(ccp2, sd_state, CCP2_PAD_SOURCE, > fmt->which); > + if (format == NULL) > + return -EINVAL; > + > *format = fmt->format; > ccp2_try_format(ccp2, sd_state, CCP2_PAD_SOURCE, format, > fmt->which); -- Regards, Laurent Pinchart