Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7067363rwl; Fri, 30 Dec 2022 03:09:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXsdmk8nyl5eRRIDZlVoUbnONjUqbq+85f+4+zHGvY7Tx5qixQDiJPInEsbPftmjnaCC8xTC X-Received: by 2002:a05:6402:34f:b0:461:7c4e:c437 with SMTP id r15-20020a056402034f00b004617c4ec437mr28484567edw.1.1672398549420; Fri, 30 Dec 2022 03:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672398549; cv=none; d=google.com; s=arc-20160816; b=oN8lj2zEf9Th/X1fsTDsiXNAJNdTJtTcN7idDMNcEHDIJNdxtcO1ex7FFxYe1tG73I FSbleGOjJSw424Cd7ek7VroduuS6NsUP201xpgBTeAxWFq1ZcHGU+woLbc2UAepH4G9F IXgOP8+rC1TK/UJ1M7yiHKfv/xGIrdG1ezUOh3LokSAN5+/UnvENOsHuMjDI1Gcqwzn3 FN5A1GmaxKYqE/gmhMMNMuJPEOCQ8KvMFrFsK6mTATUXxMbXZeeEzwKBEUS8T3+uYSjd RgAjXNFBBJuWrwQwatJOfw3Dua3G+7+n816Fs7FUjbkpjtU+vALuSHAxK55dX5jiQsPN 4mow== 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=Pmx5aC+e9IDsYYi0BG5j4m6KGO/RuKNEXxDCFZ9sdRA=; b=oOC6t/RVYyI93C+rVhdzPMBgZ+Q+Dbm0wiOlXsy6nZ8VR/mws1PKlIZlanAb2OIJGZ Sq7/w5BGf4mzeevwYturRNCwwhg3WMbU2yCkmhnLM334E3ehDZsa4470tacsWeMVdi76 ZoTyW/GOAPBra/H6zcjifRAR5Ir4u3wvDX6jGD66B2K8eAgwmPa3caLcKXClbpJtItdq BsVMc+GkkJu7ACrW8GfMg7HaVLX8bLdq85oGmFEIy6WUV0pXuf7i6Fs5FC6POvHoaa80 EBa9LIPgicZ8fR+8YMVdokwbAA6G0Y9eN5feekJHipoug6Hr+1mLQfc/1C0NiTZto1g7 bTbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U5d5j9ow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a056402165600b0046bb2fd3299si15713768edx.381.2022.12.30.03.08.54; Fri, 30 Dec 2022 03:09:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U5d5j9ow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234359AbiL3KPj (ORCPT + 63 others); Fri, 30 Dec 2022 05:15:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbiL3KPh (ORCPT ); Fri, 30 Dec 2022 05:15:37 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58891101D6; Fri, 30 Dec 2022 02:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672395336; x=1703931336; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=17bh9E50tNvTOl4ArawPNxCifke+G6sVd6QTrXMUd+4=; b=U5d5j9owXJ2cWp0gwikF8Cn4xxLuanOhTcOBkbj+t7rBlUASn7QsRb3R 2X65D9hbqyZPnm7YmqNJXmTYz0W5xyfkP5qWaAsxf0X3ZC1YasXfgHpX3 WsZDcJc6FCYiAETXFpxSYO+v0bE0fY5CDKMerqKiSTK+Wvh0c+DZFWQAC poVBIQOpEWF8uWjgonZ9xlJX71BsDZx3AzUdMrZgCi8GrnHKnSI+QQXiZ CEdJ1gWyFVtEHXWrtwWNt1mCmaZPEWlfG2GkIjMqW4EDx8jN3azsYYnFi mqUZbFSsfjKoiKveUc7AnZMGETLe8LrtIv4kfuEviYGxEJQiK97NFQ6wt w==; X-IronPort-AV: E=McAfee;i="6500,9779,10575"; a="321258650" X-IronPort-AV: E=Sophos;i="5.96,287,1665471600"; d="scan'208";a="321258650" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Dec 2022 02:15:35 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10575"; a="655826180" X-IronPort-AV: E=Sophos;i="5.96,287,1665471600"; d="scan'208";a="655826180" Received: from joe-255.igk.intel.com (HELO localhost) ([172.22.229.67]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Dec 2022 02:15:33 -0800 Date: Fri, 30 Dec 2022 11:15:32 +0100 From: Stanislaw Gruszka To: Mikko Perttunen Cc: Deepak R Varma , Saurabh Singh Sengar , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jonathan Hunter , Praveen Kumar , Thierry Reding , linux-tegra@vger.kernel.org Subject: Re: [PATCH] drm/tegra: submit: No need for Null pointer check before kfree Message-ID: <20221230101532.GA1290969@linux.intel.com> References: <864f2fdd-4289-a178-bbf1-c2a6a579c58c@kapsi.fi> <280170a7-de12-f362-cda3-11208ead0a88@kapsi.fi> <20221230091501.GA1285371@linux.intel.com> <65468c84-fc40-e4e1-0adb-ddfc23ec4fb9@kapsi.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <65468c84-fc40-e4e1-0adb-ddfc23ec4fb9@kapsi.fi> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 On Fri, Dec 30, 2022 at 12:01:23PM +0200, Mikko Perttunen wrote: > On 12/30/22 11:15, Stanislaw Gruszka wrote: > > On Wed, Dec 28, 2022 at 03:17:59PM +0200, Mikko Perttunen wrote: > > > On 12/28/22 15:08, Deepak R Varma wrote: > > > > On Wed, Dec 28, 2022 at 02:28:54PM +0200, Mikko Perttunen wrote: > > > > > On 12/27/22 19:14, Deepak R Varma wrote: > > > > > > kfree() & vfree() internally perform NULL check on the pointer handed > > > > > > to it and take no action if it indeed is NULL. Hence there is no need > > > > > > for a pre-check of the memory pointer before handing it to > > > > > > kfree()/vfree(). > > > > > > > > > > > > Issue reported by ifnullfree.cocci Coccinelle semantic patch script. > > > > > > > > > > > > Signed-off-by: Deepak R Varma > > > > > > --- > > > > > > drivers/gpu/drm/tegra/submit.c | 4 ++-- > > > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/drivers/gpu/drm/tegra/submit.c b/drivers/gpu/drm/tegra/submit.c > > > > > > index 066f88564169..06f836db99d0 100644 > > > > > > --- a/drivers/gpu/drm/tegra/submit.c > > > > > > +++ b/drivers/gpu/drm/tegra/submit.c > > > > > > @@ -680,8 +680,8 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data, > > > > > > kfree(job_data->used_mappings); > > > > > > } > > > > > > > > > > > > - if (job_data) > > > > > > - kfree(job_data); > > > > > > + kfree(job_data); > > > > > > + > > > > > > put_bo: > > > > > > gather_bo_put(&bo->base); > > > > > > unlock: > > > > > > -- > > > > > > 2.34.1 > > > > > > > > > > > > > > > > > > > > > > > > > > > > It continues to be the case that I think this transform is bad. Same applies > > > > > to the host1x patch. > > > > > > > > Hello Mikko, > > > > Thank you for responding to the patch proposal. Could you please explain why is > > > > this bad? > > > > > > > > Regards, > > > > ./drv > > > > > > > > > > > > > > Mikko > > > > > > > > > > > > > > Hi, > > > > > > it gets rid of visual hints on code paths indicating the possible liveness > > > of pointer variables. I.e., after the change, whether the pointer can be > > > NULL or not is more difficult to reason about locally, instead requiring > > > more global reasoning which is mentally more taxing. > > > > > > Since C's type system doesn't help with tracking these kinds of things, I > > > believe it is important to have these kinds of local contextual cues to help > > > the programmer. > > > > I agree with your point of view. But regarding this particular patch, > > at least on code base I can see, after free_job_data label job_done > > can not be NULL. So patch seems to be ok, but maybe changelog need to > > be different > > > > Regards > > Stanislaw > > It can be NULL; see: > > job->user_data = job_data; > job->release = release_job; > job->timeout = 10000; > > /* > * job_data is now part of job reference counting, so don't release > * it from here. > */ > job_data = NULL; > > If we go into free_job_data after this code (which happens if there is no > error, or if host1x_job_submit fails), job_data will be NULL. > > The memory is instead released in the 'put_job' label; host1x_job_put ends > up calling release_job, which does the kfree. > > (Yes, it is rather complicated..) Ok, then better to keep the check. Regards Stanislaw