[1/3] drm: property: One function call less in drm_property_create() after error detection
Message ID | 9b1e7330-f4f6-47f8-a568-eaea1624bb6f@web.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp767767dyb; Tue, 26 Dec 2023 01:39:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsFsSUzHCS0oRsmNCFulrlAlVhzP+MaugIa4KBq4B2V7ZgGjx6aAxwCiYrjW3Wh5OW+Sy8 X-Received: by 2002:a05:6a20:3713:b0:18b:d3db:7048 with SMTP id t19-20020a056a20371300b0018bd3db7048mr6820661pze.23.1703583547896; Tue, 26 Dec 2023 01:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703583547; cv=none; d=google.com; s=arc-20160816; b=IWZUUwUspl1p314oeYFE502qZPLVbAIRzhx/4KJsRTvpuChp6xNuq5lHEL0aikC3pz 3By9Qs0BABdzEu+MSFqGPK2tMAt6qzKx9PBnMFFP/7bCzhZ1UQTTIFgn1cY5KxpumWbm vK81WrZ8jQxt1vtdwcI3V1WK0UhhPZJSv1bL/aZ7Si5SK5rJ7dB/PvsTtxoYn974eHtL ypJ2z9H8c9cVP10zuFbZ8HyprRFwWypUCOCdn/UBOzUgIXkCU0bbytXBzsTKFmaOftnU uII+HbFYKWx1xbj33mSJiY8sOPD3yEAuigC3PxBshbdHsj/2o1G4Q1/wUFFqnG2QtXMm Q1xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=UdSpUrVCia57gGLp3j38cgsVMvnNbpTLnwQcX9gie8o=; fh=60vkliJMaNMQ9vWVETCOLiNxdcVoGFT7eofn8OFibpU=; b=J21hKIuuCqKEQYh9jBJFTVIExEMmDR7+xbNgUv4+ghUL88HQ838sKG8IDHTlHuk9ap ZutcRQND/mdvEAFbufwhXYVxRjhPBUEPtHYpCy5Vk/sy9YFX2Oe65v6KSgkU9V+VDOKc kvpLjtr4q3RLao37LdTMJcoeQfE/KhoKuJhAOhU43lMqHYBcObPxCr7UBQyM7S1WULuL bNQI2BmYkMCccHHI7ufzhdPUir4IIvckXsSfIt9rC8D5rXVvnlTPOipFInR3qwSCXhFv SDCRQY6+GchNfQRvihs7bz+udAVmFnhfmg0aaVGwyVllsrpSJYWwN8UBCtInYBs1MfyI 6Xhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=Wy+H4r4G; spf=pass (google.com: domain of linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x4-20020a17090aca0400b0028bf1c4a1e5si8735976pjt.113.2023.12.26.01.39.07 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 01:39:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=Wy+H4r4G; spf=pass (google.com: domain of linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11446-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AA1E1282F5F for <ouuuleilei@gmail.com>; Tue, 26 Dec 2023 09:39:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 179C54D58F; Tue, 26 Dec 2023 09:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="Wy+H4r4G" X-Original-To: linux-kernel@vger.kernel.org Received: from mout.web.de (mout.web.de [212.227.17.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 871A44D10D; Tue, 26 Dec 2023 09:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703583504; x=1704188304; i=markus.elfring@web.de; bh=qqBCvkgxbSr3g6FTVllb7hWAQXmgVICHt5PVFl7CIWM=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=Wy+H4r4Gnaa7y8tBPP7pvGH9Vec+3s9dvNs1B7LVWc/iT6edD5t8cI3E4DBpOLTV qhyV+uMBT/XL3i89SdIhhxywBBUObocgZ32fJHx9VfYhBhdp5yNS5dwXdSMFAju51 FcIFnh4TBrEVloMrstRrQ2/XCqA8qfcN212+mEoUdDxvp1CsyWlkJ24VJns08R+lh eLZLEVJCnAStJAZ4UJ1byJUSaAEswW143Fk+ACvx1j0ZuXz/UZXhG/NhPlsm8VO9n bfT17tpHgSLnT96f0myHggbY8uY9a4EIfb+Y5BpxzEdSRzLJJDGr4QcXvzoZCoP/G BoYy0kHI3wnHNkMbuA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MC0LH-1rQ3aP0NaP-00CKaS; Tue, 26 Dec 2023 10:38:24 +0100 Message-ID: <9b1e7330-f4f6-47f8-a568-eaea1624bb6f@web.de> Date: Tue, 26 Dec 2023 10:38:22 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/3] drm: property: One function call less in drm_property_create() after error detection Content-Language: en-GB From: Markus Elfring <Markus.Elfring@web.de> To: dri-devel@lists.freedesktop.org, kernel-janitors@vger.kernel.org, Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@gmail.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de> Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr References: <ff7ce5d0-59fa-470c-8dd6-68dbe65c18e5@web.de> In-Reply-To: <ff7ce5d0-59fa-470c-8dd6-68dbe65c18e5@web.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:iDixZmNvylQDuMt0skzUFKjo8Mh89iiU1EhN0o+/2elM/jOlggR 6muOk7JjgmGLlXj3ITzr5rhHM9PHeCLjkWxFXiVhflFrt6iRboOIWS7Dl5KJDHi1vkOUj71 pvU/i0C+PKKkNZ+eU5BzCX/eLI33iBrs+IvDwscaU8Vvv/c0iWdWouXu1c0vmuzAwXne416 rBGEr9tTaR33LkfrfkioA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:d/X1dljrE+A=;DqE9o4o4RjEHkhdE3U4ZQnuaFTY X7BtY+Blaevtp8Ogi98aTZqmzApKK5NoowuUnky/rLGUjzcuMNPkp3opQGYwAZCAaW+sUVGew x3QvEl96i7st7xV4gRQ7zLiGuqjBArZOkF7UBpLEnnPbPCH7Nea3zu9TstckRmC00FKy+G4W2 ENEbw+k1nTIADPLkzT3JBEDXFE5Va4fMIAAvo8KWdMhZAHbQ1C+S9rXgfVFpB45bj7ZlEiKJV S4TgV/IOkq0grOPVdAJvFmBPENGwPltYqeh70ZIa3A2Y2GGaQvglcni30hejMmGsJBezMEDqX crP+A5P18C9tiXaEHBUkwOhhp06LRvodzsoSVgt50mJm4xIrQM/3xochjkNmcITtL3P7pDB5O UUuIz6X43Trn1F6NVDAgNNlOSkN+69CkQeVwoZpc6Hq3DZihvs5EMifC4iIvvDFZYDl4hOxVG inDeWb1NdllB5EVpTDf5SUmsxPQrCPdb/LmVjSItrUDx7yp+F9hgxWP95aM7FCUZBc/56VAAc O2YQ3P3Ia+EDZJXJSw8EdqW9s0UMfP29uEjUvTjnB4UaPJhFn44xT5/BjkqM9zMc+o+9hMcGv KniLAhWq8b+ElonJTBF9sdYf0iD7xSLj7QYBgML8UqoBjulyCGylO7hkSQNFI7aJPIDU69p43 805KlV3/znVyiISBn9VkzwvaRpmCJhTVBeCOAkaIXdjz6kdSk5ApPWguqT3vFdIW4AhFAAvOy 3CCVqHLBjR4ChxO09YO13+z0JKyXk4QlEvry+VpBGoSqMnTCGG2GrjfI7ZGYrdrAIlvCMGTyK RWdH0HK1XOe5WjBF+7Hmgg2UpTWMMyZzdRTgDXvpCeEpUAezdkXKUL85RxmpXgVc9Gx9+eVug jym4+HsekxTWq/nCXtVazhUnSqOXK2Q0lvGjIS/YgjpnwPodLBrITXzXpeOxjY0FLJZ1JRJpz eaNQEQ== X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786336822210316629 X-GMAIL-MSGID: 1786336822210316629 |
Series |
[1/3] drm: property: One function call less in drm_property_create() after error detection
|
|
Commit Message
Markus Elfring
Dec. 26, 2023, 9:38 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 26 Dec 2023 08:44:37 +0100 The kfree() function was called in one case by the drm_property_create() function during error handling even if the passed data structure member contained a null pointer. This issue was detected by using the Coccinelle software. Thus use another label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/drm_property.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.43.0
Comments
On 2023-12-26 10:38, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 26 Dec 2023 08:44:37 +0100 > > The kfree() function was called in one case by the > drm_property_create() function during error handling > even if the passed data structure member contained a null pointer. > This issue was detected by using the Coccinelle software. > > Thus use another label. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/drm_property.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c > index 596272149a35..3440f4560e6e 100644 > --- a/drivers/gpu/drm/drm_property.c > +++ b/drivers/gpu/drm/drm_property.c > @@ -117,7 +117,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, > property->values = kcalloc(num_values, sizeof(uint64_t), > GFP_KERNEL); > if (!property->values) > - goto fail; > + goto free_property; > } > > ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); > @@ -135,6 +135,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, > return property; > fail: > kfree(property->values); > +free_property: > kfree(property); > return NULL; > } > -- > 2.43.0 > This change is pointless at best, kfree(NULL) works fine. Out of curiosity, what exactly did Coccinelle report?
>> The kfree() function was called in one case by the >> drm_property_create() function during error handling >> even if the passed data structure member contained a null pointer. >> This issue was detected by using the Coccinelle software. >> >> Thus use another label. … >> +++ b/drivers/gpu/drm/drm_property.c >> @@ -117,7 +117,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, >> property->values = kcalloc(num_values, sizeof(uint64_t), >> GFP_KERNEL); >> if (!property->values) >> - goto fail; >> + goto free_property; >> } >> >> ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); >> @@ -135,6 +135,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, >> return property; >> fail: >> kfree(property->values); >> +free_property: >> kfree(property); >> return NULL; >> } … > This change is pointless at best, kfree(NULL) works fine. * Would you interpret such a special function call as redundant? * Do you find advices applicable from another information source also for this function implementation? https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources > Out of curiosity, what exactly did Coccinelle report? Some SmPL scripts from my own selection tend to point questionable implementation details out. Regards, Markus
On 2024-01-03 17:24, Markus Elfring wrote: > >> Out of curiosity, what exactly did Coccinelle report? > > Some SmPL scripts from my own selection tend to point questionable implementation details out. That doesn't answer my question. Without seeing the actual Coccinelle report, I'll assume that it didn't actually call for this change.
>>> Out of curiosity, what exactly did Coccinelle report? >> >> Some SmPL scripts from my own selection tend to point questionable implementation details out. > > That doesn't answer my question. It should. > Without seeing the actual Coccinelle report, There is no “official” report according to the discussed patch which is triggered by known advices for the application of labels in goto chains. > I'll assume that it didn't actually call for this change. Software development opinions are evolving accordingly. Regards, Markus
On 2024-01-03 19:08, Markus Elfring wrote: > >> Without seeing the actual Coccinelle report, > > There is no “official” report according to the discussed patch which is triggered > by known advices for the application of labels in goto chains. The commit log says: This issue was detected by using the Coccinelle software. Either that's inaccurate then, or you should be able to provide the corresponding output from Coccinelle.
> The commit log says: > > This issue was detected by using the Coccinelle software. > > Either that's inaccurate then, No. > or you should be able to provide the corresponding output from Coccinelle. Do you find data (like the following) more helpful for the adjustment of affected implementation details? Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> LANG=C git status && spatch …/Projekte/Coccinelle/janitor/show_jumps_to_kfree_with_null_pointer.cocci drivers/gpu/drm/drm_property.c HEAD detached at next-20240104 … @@ -114,9 +114,6 @@ struct drm_property *drm_property_create property->dev = dev; if (num_values) { - property->values = kcalloc(num_values, sizeof(uint64_t), - GFP_KERNEL); - if (!property->values) goto fail; } @@ -133,8 +130,6 @@ struct drm_property *drm_property_create list_add_tail(&property->head, &dev->mode_config.property_list); return property; -fail: - kfree(property->values); kfree(property); return NULL; } How do you think about to extend the application of script variants for the semantic patch language? Regards, Markus
On Wed, Jan 03, 2024 at 06:18:13PM +0100, Michel Dänzer wrote: > On 2024-01-03 17:24, Markus Elfring wrote: > > > >> Out of curiosity, what exactly did Coccinelle report? > > > > Some SmPL scripts from my own selection tend to point questionable implementation details out. > > That doesn't answer my question. > > Without seeing the actual Coccinelle report, I'll assume that it didn't actually call for this change. This isn't one of the Coccinelle scripts which ship with the kernel, it's something that Markus wrote himself. regards, dan carpenter
diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c index 596272149a35..3440f4560e6e 100644 --- a/drivers/gpu/drm/drm_property.c +++ b/drivers/gpu/drm/drm_property.c @@ -117,7 +117,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, property->values = kcalloc(num_values, sizeof(uint64_t), GFP_KERNEL); if (!property->values) - goto fail; + goto free_property; } ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); @@ -135,6 +135,7 @@ struct drm_property *drm_property_create(struct drm_device *dev, return property; fail: kfree(property->values); +free_property: kfree(property); return NULL; }