Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2033842imb; Sun, 3 Mar 2019 15:35:17 -0800 (PST) X-Google-Smtp-Source: APXvYqz42Asvi3mm/rb04DwaPY7AolTOR8grYjG8rxWepIDCsHZBa8dFqR3ttJu6unSbewa3E3SH X-Received: by 2002:a63:3648:: with SMTP id d69mr15898725pga.314.1551656117082; Sun, 03 Mar 2019 15:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551656117; cv=none; d=google.com; s=arc-20160816; b=Hhiv7uvCe1XWFReuEnhQo0zpniuvPuYZ5HKE1D+vBO4QqXjg7hqQrA5OeMIezSYkKx ufvedXYLHYyCM38b2BpDsdyhsqBE1qJgrRI9dXAWkpUyjsJP9S3yl6qmF1zqkI2Ucnx+ wSI11cMtC7dPFoFC9NmJgGjno8uMQnCUG/9XsD9TlQESlUcDJjx4cEw44kQEN8ZfwG1T cUoMwHFm4hksQ8w0Ws9q+Q5FOXzS2KelFYqdqLYZX8LhpUFb9f+rQSAmAp7Uy7suhOym +DrcPCVJd3zZ8Z6rS5MsU4iE6wsgPNCHKO499ZCdZaRDLUMT1dipxsAX6Ud8JWpw07C9 pXCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=R//LO8kId07yQdsqTF+AJMOpyUrtgzT1E+u2peSrLhs=; b=nUPJHh7z86BFd/EtuZLIS9o8i4nI1p7Fo6C2pYm++Y9eQcVkNnFLJpY/r0vptP3x67 N6n1QFt+leCcYzfmjGjZy5ANNPTDMKjDk77LnBWt4NtyzRRJir3Hf1d16rNNGrvyMeXQ ibECgbdZAi+rt/QTnZcbuGfH7Ji6arM+kM81tRxtR00K1B92rktWENDFZtmpY9zP+hV6 +BGznDQs7hs6x/1R22mRlePYz6F2TsmJABNCpxaRiWlSWfe5HSvj5Pb47KmxqMFJztDz 1xkE7G2EVAltqpavX/0SLofftseFDqYFf+UHkLdGbQo+zYaH3fGKy0v1MwHOtHlRJFH1 eXDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 10si3829567pgn.558.2019.03.03.15.35.01; Sun, 03 Mar 2019 15:35:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726037AbfCCXe2 (ORCPT + 99 others); Sun, 3 Mar 2019 18:34:28 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44888 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbfCCXe2 (ORCPT ); Sun, 3 Mar 2019 18:34:28 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 60E932802CD Message-ID: <1f7ab3d0a759c583fc33a83ee24ed780e40ce7a1.camel@collabora.com> Subject: Re: [PATCH] Remove deductively redundant NULL pointer checks From: Ezequiel Garcia To: Shaobo He , linux-media@vger.kernel.org Cc: Philipp Zabel , Mauro Carvalho Chehab , Rick Chang , Bin Liu , Matthias Brugger , Tiffany Lin , Andrew-CT Chen , Kieran Bingham , Mikhail Ulyanov , Jacob chen , Heiko Stuebner , Kyungmin Park , Kamil Debski , Andrzej Hajda , Andrzej Pietrasiewicz , Jacek Anaszewski , Benoit Parrot , Hans Verkuil , Kees Cook , Anton Leontiev , Simon Horman , Kuninori Morimoto , Tomasz Figa , Sakari Ailus , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , "open list:MEDIA DRIVERS FOR RENESAS - FDP1" , "open list:ARM/Rockchip SoC support" Date: Sun, 03 Mar 2019 20:34:09 -0300 In-Reply-To: <1551228250-36426-1-git-send-email-shaobo@cs.utah.edu> References: <1551228250-36426-1-git-send-email-shaobo@cs.utah.edu> Organization: Collabora Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-02-26 at 17:43 -0700, Shaobo He wrote: > The fixes included in this commit essentially removes NULL pointer > checks on the return values of function `get_queue_ctx` as well as > `v4l2_m2m_get_vq` defined in file v4l2-mem2mem.c. > > Function `get_queue_ctx` is very unlikely to return a NULL pointer > because its return value is an address composed of the base address > pointed by `m2m_ctx` and an offset of field `out_q_ctx` or `cap_q_ctx`. > Since the offset of either field is not 0, for the return value to be > NULL, pointer `m2m_ctx` must be a very large unsigned value such that > its addition to the offset overflows to NULL which may be undefined > according to this post: > https://wdtz.org/catching-pointer-overflow-bugs.html. Moreover, even if > `m2m_ctx` is NULL, the return value cannot be NULL, either. Therefore, I > think it is reasonable to conclude that the return value of function > `get_queue_ctx` cannot be NULL. > > Given the return values of `get_queue_ctx` not being NULL, we can follow > a similar reasoning to conclude that the return value of > `v4l2_mem_get_vq` cannot be NULL since its return value is the same > address as the return value of `get_queue_ctx`. Therefore, this patch > also removes NULL pointer checks on the return values of > `v4l2_mem_get_vq`. > > Signed-off-by: Shaobo He Hi Shaobo, It seems this is v2 of 1551128631-19713-1-git-send-email-shaobo@cs.utah.edu, and it should be marked as such. Do you think you can read Documentation/process/submitting-patches.rst, for your future patches? Also, two comments... > drivers/media/platform/coda/coda-common.c | 4 ---- > drivers/media/platform/imx-pxp.c | 7 ------- > drivers/media/platform/m2m-deinterlace.c | 7 ------- > drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 7 ------- > drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 7 ------- > drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 13 ------------- > drivers/media/platform/mx2_emmaprp.c | 7 ------- > drivers/media/platform/rcar_fdp1.c | 3 --- > drivers/media/platform/rcar_jpu.c | 8 -------- > drivers/media/platform/rockchip/rga/rga.c | 4 ---- > drivers/media/platform/s5p-g2d/g2d.c | 4 ---- > drivers/media/platform/s5p-jpeg/jpeg-core.c | 7 ------- > drivers/media/platform/sh_veu.c | 2 -- > drivers/media/platform/ti-vpe/vpe.c | 7 ------- > drivers/media/platform/vicodec/vicodec-core.c | 5 ----- > drivers/media/platform/vim2m.c | 7 ------- > drivers/media/v4l2-core/v4l2-mem2mem.c | 4 ---- > 17 files changed, 103 deletions(-) > > diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c > index 7518f01..ee1e05b 100644 > --- a/drivers/media/platform/coda/coda-common.c > +++ b/drivers/media/platform/coda/coda-common.c > @@ -696,8 +696,6 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f, > struct vb2_queue *vq; > > vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); > - if (!vq) > - return -EINVAL; > > q_data = get_q_data(ctx, f->type); > if (!q_data) > @@ -817,8 +815,6 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv, > ctx->quantization = f->fmt.pix.quantization; > > dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); > - if (!dst_vq) > - return -EINVAL; > > /* > * Setting the capture queue format is not possible while the capture > diff --git a/drivers/media/platform/imx-pxp.c b/drivers/media/platform/imx-pxp.c > index c1c2554..d079b3c 100644 > --- a/drivers/media/platform/imx-pxp.c > +++ b/drivers/media/platform/imx-pxp.c > @@ -1071,13 +1071,8 @@ static int pxp_enum_fmt_vid_out(struct file *file, void *priv, > > static int pxp_g_fmt(struct pxp_ctx *ctx, struct v4l2_format *f) > { > - struct vb2_queue *vq; > struct pxp_q_data *q_data; > > - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); > - if (!vq) > - return -EINVAL; > - It seems your patch also removes unused code, but this is not really explained in the commit log. Perhaps it is better to split all these changes on their own patch: one patch to remove dead code, and then another patch to remove unneeded null checks. And also, I think you should add some comments, either in v4l2_m2m_get_vq's declaration or definition, explaining that the return value cannot be NULL. I have to say: I'm not a fan of "improvement" patches in code paths that are anything but hot... but knock yourself out! Thanks, Eze