Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7031472rwl; Fri, 30 Dec 2022 02:29:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXtICkl+czw61sZPv7rkKfdiudQjDEkPRcfga+c0f4duRYCUl7ETRUz77/JccT1oHgZ27JVr X-Received: by 2002:a17:906:700f:b0:7c0:d1cb:2165 with SMTP id n15-20020a170906700f00b007c0d1cb2165mr26549792ejj.56.1672396157621; Fri, 30 Dec 2022 02:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672396157; cv=none; d=google.com; s=arc-20160816; b=Xexl12tXJ7T0qgW2e6Mh/Z92TJYspgcEemaGR1+idy5fCb4K6dykc2GjH+LBcQk5KV e7x4Sg5j8MMAMPvkHtmu3ofIDlmkhuXbJ+BSpK6FeLmk05Jbk44vMLebThPTZOvAtBuW 9mg35azpbnNXu9W0ieSXYBI3Kek8sxNXkROVW5BVpwYY9OyE1VKYNHnXglmIK7W+U6+z +EPgF/y1k86fJyXolahQKl9/rZQFIDEyIAFZQZqR2h5pCFD2rOXttXvKZCworvCVrYD8 14oRoM0kfXY4SGMFwgCyXJcDk9yGt1ZuRXfP+1qhuCYot3zCol9IDcx/ciH9VNwfx8sS QNsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/XXcsqpwwhzC7dXBuKnRV/g66zh19Xq0hf1OrfkeqS8=; b=Rbup2GHxt789OhsVbh9lY+e9vmZB5Yq5aV0V2B/mPogcHMnXBARRF/O0qt81BIbu/1 syFtjBl6hMLH0aPyW7v9y7pWQZNLsI51nRAaq8ZD75l2gNTfKu6Vc+hiiwqhQNBiSuU/ qRVnrGNlI1LW5dS6s7auUCxRIgMskWJAbCNfNLXvuUNHNHMckDPhXxk09S9uXbZFx6kl tmNsrkN/bSuFL724kEnggcYAeZaQhnC7TChhP67HZbucqQxxxuxFgxGNvltm3yat8xUt JiuL1+fYLqhOwFe1Z9wdLKBzIj8iu8RB44PiDULQygR10unokMb5fMfvlsXzn1Etb5s2 pLlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=UMpUouaY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kapsi.fi Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a056402440b00b00468f6919522si21020548eda.564.2022.12.30.02.29.02; Fri, 30 Dec 2022 02:29:17 -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=fail header.i=@kapsi.fi header.s=20161220 header.b=UMpUouaY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kapsi.fi Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234920AbiL3KBk (ORCPT + 63 others); Fri, 30 Dec 2022 05:01:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234745AbiL3KBg (ORCPT ); Fri, 30 Dec 2022 05:01:36 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9939519C32; Fri, 30 Dec 2022 02:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/XXcsqpwwhzC7dXBuKnRV/g66zh19Xq0hf1OrfkeqS8=; b=UMpUouaYbyb6lFYmh/OQDwAWoM z/4Kej+eMAG6ox29+YT0uvZDThoK9B8F99YFJ+n2HNmAZKuL9DjKA9jQKHkRXs0tG/n1/yU/ud2zI q0xfsvK//rj6alYEdenP3OWbjVcTQverVSA1oLylSuExwD2GUiQgvEeRHqzL21bHCNMX28zkR2H54 Fn/Lj9I7d08086BNegBI2vqxhButaW9+XoTwmV8Ez9bg/WWQ/bgwQ8F8UuMDp3QT3ZcFKDiVLHNVh cA62BwI7m5UF67tlE+z1pWKD4gpcEN3ikiaqcaufGkPosrY9+5o9G56c6+VbnVgJebp6I3u/97RQ8 dZuyc4KA==; Received: from 91-158-25-70.elisa-laajakaista.fi ([91.158.25.70] helo=[192.168.1.10]) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pBCCa-00Gqsu-51; Fri, 30 Dec 2022 12:01:24 +0200 Message-ID: <65468c84-fc40-e4e1-0adb-ddfc23ec4fb9@kapsi.fi> Date: Fri, 30 Dec 2022 12:01:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] drm/tegra: submit: No need for Null pointer check before kfree Content-Language: en-US To: Stanislaw Gruszka Cc: Deepak R Varma , Praveen Kumar , Saurabh Singh Sengar , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jonathan Hunter , Thierry Reding , linux-tegra@vger.kernel.org References: <864f2fdd-4289-a178-bbf1-c2a6a579c58c@kapsi.fi> <280170a7-de12-f362-cda3-11208ead0a88@kapsi.fi> <20221230091501.GA1285371@linux.intel.com> From: Mikko Perttunen In-Reply-To: <20221230091501.GA1285371@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 91.158.25.70 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS 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 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..) Thanks, Mikko