Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4528209rwl; Wed, 28 Dec 2022 05:31:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXvG6LuQENAEhHtPrvTtt5oiiVR22c9R7XeN6LU/DJBDlPFLg4fmMUDgnCborw8VQtkkbUng X-Received: by 2002:a17:906:2596:b0:7c1:6344:845 with SMTP id m22-20020a170906259600b007c163440845mr17084165ejb.34.1672234288451; Wed, 28 Dec 2022 05:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672234288; cv=none; d=google.com; s=arc-20160816; b=jmWaxpKlpbM1klpgp3hqyA6Cr29ARZlg3HP52+IAhf+kDmAnipJFcPPmZb1lUSgAzs zuFWmmP/Q8jNVKCGuBYk17f1FZL9yK0LJF8PjQQU2vTJStTMmXreS9p1GokyKMymSE0j 68WBU2hSRlVRZNAFJn3bGbQWviHj+bmSKwWPnBAdCN3x0pgGuVOV5GQIsWYlEhdf04ai VmBS79uvdZwHXMfXAPEiBJ1WtYrYrCcq4PPsrRd3juNTgLJSR1m1QHPTyZwWnZrmFLzK /aS62zMNkAOx3xxkDydpz6WaNenhrJ1VgyssYL7H7jUH6ks579yxP69gxJ6zBWXSONq2 K0KQ== 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=JzEiDFI5EH6PN63FRnjKDVSaqSSqZ6cbt0nBtY//C7I=; b=cQ5Ryvmt6jE9gqQ+/3vyVyeH1gxQJeHasZScp4sqpwLkz50muKiRpwYFvqnq+hFnKx TUbYlHC1YxszJ2SBK8IM60x6EaN1YB2mC1YIK8dxTgXQje76bjUTLuAwVveQAJbnHM2x n0lfQDVOh+q9cgWuuMCY1m7aqJdD44IniGNBGdIDCpLCiblYJob+8Y97en89hDbFeCIn tx5Pe3lk4MtvsxR0DFMu7edGIO1UZT0sSyYpZrPCk/zL7gxAsW/OK62uEFMTeggMbYqv /lOgmvaxBFQizW8XnJ8mDk4uvFH4gIBqCphDbCtriFL5Z0XwwY4x0iUA1zmXflo+M/Fa d5Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=h2RnegPW; 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 xe12-20020a170907318c00b007c1031bec6esi12392505ejb.857.2022.12.28.05.31.11; Wed, 28 Dec 2022 05:31:28 -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=h2RnegPW; 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 S229864AbiL1NSL (ORCPT + 65 others); Wed, 28 Dec 2022 08:18:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbiL1NSI (ORCPT ); Wed, 28 Dec 2022 08:18:08 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 306F8B36; Wed, 28 Dec 2022 05:18:07 -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=JzEiDFI5EH6PN63FRnjKDVSaqSSqZ6cbt0nBtY//C7I=; b=h2RnegPWDsKYsJUcS62pCEUwzY 7KBi2vS+4R0PubsiVVSummaOQh7e2XbmM0JemyvxQ5sqF+dRIzXLxCeUWHp5Qj/LXLd8rC3niw5t7 wp1vUTWF8T/Ej1T1MkMrztJbivXSJgSaX/6nr6m8Hcb0urJNzD0fJfKt3j3bI87UOyQM2w3iiM9xM Qv5mmeDGXnTjiSSyni09PtrKVHyyrIQyEZVcTwE1doB0Oj7cd9I4JIM1Bos70FNWhqCSEbKrYTwit 7vE30X31wtYyiCE0cMUpYkb7fKtqg9p7Cd/wmT6zT0UdqYaP8jpa+we9ZPCEn6qfF25ksmOSudC5m T44MPmHQ==; 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 1pAWJk-008grl-2M; Wed, 28 Dec 2022 15:18:00 +0200 Message-ID: <280170a7-de12-f362-cda3-11208ead0a88@kapsi.fi> Date: Wed, 28 Dec 2022 15:17:59 +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: Deepak R Varma Cc: Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Saurabh Singh Sengar , Praveen Kumar References: <864f2fdd-4289-a178-bbf1-c2a6a579c58c@kapsi.fi> From: Mikko Perttunen In-Reply-To: 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/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. Mikko