cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Lorenzo Stoakes <lstoakes@gmail.com>,
	kernel-janitors@vger.kernel.org, linux-kselftest@vger.kernel.org,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	Jay Kamat <jgkamat@fb.com>, Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeelb@google.com>, Shuah Khan <shuah@kernel.org>,
	Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [cocci] [PATCH] selftests: cgroup: Fix exception handling in test_memcg_oom_group_score_events()
Date: Sun, 26 Mar 2023 10:15:31 +0200	[thread overview]
Message-ID: <5b7921c9-ee5d-c372-b19b-2701bcf33148@web.de> (raw)
In-Reply-To: <fffcd98a-bb73-41cd-8545-0f2c55dd38f9@lucifer.local>

>> The label “cleanup” was used to jump to another pointer check despite of
>> the detail in the implementation of the function
>> “test_memcg_oom_group_score_events” that it was determined already
>> that a corresponding variable contained a null pointer.
>
> This is poorly writte and confusing.

A special source code combination was detected.


Reconsidering repeated pointer checks with SmPL
https://lore.kernel.org/cocci/f9303bdc-b1a7-be5e-56c6-dfa8232b8b55@web.de/
https://sympa.inria.fr/sympa/arc/cocci/2023-03/msg00017.html



> Something like 'avoid unnecessary null check/cg_destroy() invocation'
> would be far clearer.

I (or another interested contributor) can integrate such information into
a subsequent patch if the change acceptance will grow accordingly.


>> 1. Thus return directly after a call of the function “cg_name” failed.
>
> This feels superfluious.

Under which circumstances would you care more for the advice
“If there is no cleanup needed then just return directly.”
from the section “Centralized exiting of functions”?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.3-rc3#n532


>> 2. Use an additional label.
>
> This also feels superfluious.

The marking of special source code positions is probably required for
the presented design goal.


>> 3. Delete a questionable check.
>
> This seems superfluois and frankly, rude. It's not questionable,

Can you find the combination of code fragments like “if (!memcg)”
and “if (memcg)” suspicious?


> it's readable, you should try to avoid language like 'questionable' when the
> purpose of the check is obvious.

I tend to prefer an other known design variant at this place.


>> This issue was detected by using the Coccinelle software.
>>
>> Fixes: a987785dcd6c8ae2915460582aebd6481c81eb67 ("Add tests for memory.oom.group")
>
> Fixes what in the what now?

1. Check repetition (which can be undesirable)

2. Can a cg_destroy() call ever work as expected if a cg_create() call failed?


>> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
>> @@ -1242,12 +1242,11 @@ static int test_memcg_oom_group_score_events(const char *root)
>>  	int safe_pid;
>>
>>  	memcg = cg_name(root, "memcg_test_0");
>> -
>>  	if (!memcg)
>> -		goto cleanup;
>> +		return ret;
>>
>>  	if (cg_create(memcg))
>> -		goto cleanup;
>> +		goto free_cg;
>>
>>  	if (cg_write(memcg, "memory.max", "50M"))
>>  		goto cleanup;
>> @@ -1275,8 +1274,8 @@ static int test_memcg_oom_group_score_events(const char *root)
>>  	ret = KSFT_PASS;
>>
>>  cleanup:
>> -	if (memcg)
>> -		cg_destroy(memcg);
>> +	cg_destroy(memcg);
>> +free_cg:
>>  	free(memcg);
>>
>>  	return ret;
>> --
> I dislike this patch, it adds complexity for no discernible purpose and
> actively makes the code _less_ readable and in a self-test of all places (!)

It seems that there is a conflict to resolve also according to another
information source.
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#MEM12C.Considerusingagotochainwhenleavingafunctiononerrorwhenusingandreleasingresources-CompliantSolution%28POSIX,GotoChain%29


Regards,
Markus

  parent reply	other threads:[~2023-03-26  8:16 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 17:36 [cocci] Reconsidering repeated pointer checks with SmPL Markus Elfring
2023-03-16 20:07 ` [cocci] [PATCH 0/4] powerpc/4xx: Adjustments for four function implementations Markus Elfring
2023-03-25 15:30   ` [cocci] [PATCH v2 " Markus Elfring
2023-03-25 15:36     ` [cocci] [PATCH v2 1/4] powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() Markus Elfring
2023-03-25 15:38     ` [cocci] [PATCH v2 2/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pcix_bridge() Markus Elfring
2023-03-25 15:40     ` [cocci] [PATCH v2 3/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pci_bridge() Markus Elfring
2023-03-25 15:42     ` [cocci] [PATCH v2 4/4] powerpc/4xx: Delete unnecessary variable initialisations in four functions Markus Elfring
2024-01-05 17:42     ` [cocci] [PATCH v2 0/4] powerpc/4xx: Adjustments for four function implementations Markus Elfring
     [not found] ` <0981dc33-95d0-4a1b-51d9-168907da99e6@web.de>
2023-03-17 13:11   ` [cocci] [PATCH] powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() Nathan Lynch
2023-03-17 14:20     ` [cocci] " Markus Elfring
2023-03-17 15:41       ` Nathan Lynch
2023-03-18  7:30         ` Markus Elfring
2023-03-20 15:38           ` Nathan Lynch
2023-03-21  6:54             ` Markus Elfring
2023-03-21 10:30               ` [cocci] [PATCH v2 0/2] powerpc/pseries: Fixes for " Markus Elfring
2023-03-25 13:40                 ` [cocci] [PATCH resent " Markus Elfring
2023-03-25 13:42                   ` [cocci] [PATCH resent v2 1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() " Markus Elfring
2023-03-25 13:44                   ` [cocci] [PATCH resent v2 2/2] powerpc/pseries: Fix exception handling " Markus Elfring
2024-01-05 17:19                   ` [cocci] [PATCH resent v2 0/2] powerpc/pseries: Fixes for " Markus Elfring
     [not found] ` <afe30fc6-04c9-528c-f84a-67902b5a6ed8@web.de>
2023-03-19 11:40   ` [cocci] [PATCH] RDMA/siw: Fix exception handling in siw_accept_newconn() Leon Romanovsky
     [not found]     ` <1c06e86d-1468-c11a-8344-9563ad6047b5@web.de>
2023-03-19 14:11       ` Leon Romanovsky
     [not found]         ` <a03c1d04-a41e-7722-c36a-bd6f61094702@web.de>
     [not found]           ` <20230319173716.GF36557@unreal>
2023-03-20  8:19             ` [cocci] " Markus Elfring
     [not found] ` <f0f96f74-21d1-f5bf-1086-1c3ce0ea18f5@web.de>
2023-03-19 11:41   ` [cocci] [PATCH] RDMA/erdma: Fix exception handling in erdma_accept_newconn() Leon Romanovsky
2023-03-19 13:36   ` Cheng Xu
2023-03-19 14:00     ` Markus Elfring
2023-03-19 20:00 ` [cocci] [PATCH 0/2] irqchip/gic-v4: Adjustments for two function implementations Markus Elfring
2023-03-25 10:25   ` [cocci] [PATCH resent " Markus Elfring
2023-03-25 10:27     ` [cocci] [PATCH resent 1/2] irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_irqs() Markus Elfring
2023-03-25 10:30     ` [cocci] [PATCH resent 2/2] irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_sgis() Markus Elfring
     [not found] ` <521b63e1-9470-58ef-599e-50a1846e5380@web.de>
     [not found]   ` <ZBffPEIWcmYcaXR3@google.com>
2023-03-20  8:55     ` [cocci] [PATCH] Input: iforce - Fix exception handling in iforce_usb_probe() Markus Elfring
     [not found]     ` <6b5de584-b31f-9045-a438-b42da350326b@I-love.SAKURA.ne.jp>
     [not found]       ` <ZBf3oSgJP8bLmhG0@google.com>
2023-03-25 10:12         ` [cocci] [PATCH resent] " Markus Elfring
2023-03-20 16:47 ` [cocci] [PATCH 0/2] md/raid: Adjustments for two function implementations Markus Elfring
2023-03-25  9:20   ` [cocci] [PATCH resent " Markus Elfring
2023-03-25  9:22     ` [cocci] [PATCH resent 1/2] md/raid1: Fix exception handling in setup_conf() Markus Elfring
2023-03-25  9:24     ` [cocci] [PATCH resent 2/2] md/raid10: " Markus Elfring
     [not found]     ` <CAPhsuW7JZDps_fTHyCabjfG4YjzDVEW_41u6d+9mdc2CAJv_Kw@mail.gmail.com>
2023-03-29  5:32       ` [cocci] [0/2] md/raid: Adjustments for two function implementations Markus Elfring
2023-03-21 16:07 ` [cocci] [PATCH 0/3] scsi: message: fusion: Adjustments for four " Markus Elfring
2023-03-25  9:00   ` [cocci] [PATCH resent " Markus Elfring
2023-03-25  9:03     ` [cocci] [PATCH resent 1/3] scsi: message: fusion: Return directly after input data validation failed in four functions Markus Elfring
2023-03-25  9:07     ` [cocci] [PATCH resent 2/3] scsi: message: fusion: Delete a redundant pointer check " Markus Elfring
2023-03-25  9:10     ` [cocci] [PATCH resent 3/3] scsi: message: fusion: Delete an unnecessary variable initialisation " Markus Elfring
     [not found] ` <e3aaeecf-8e74-2e74-c58a-d80e153e98f9@web.de>
2023-03-22  9:36   ` [cocci] [PATCH] media: hantro: HEVC: Fix exception handling in tile_buffer_reallocate() Benjamin Gaignard
2023-03-22 14:45     ` Markus Elfring
2023-03-22 19:20 ` [cocci] [PATCH] btrfs: Fix exception handling in relocating_repair_kthread() Markus Elfring
2023-03-25  8:25   ` [cocci] [PATCH resent] " Markus Elfring
2023-03-22 21:20 ` [cocci] [PATCH] ufs: Fix exception handling in ufs_fill_super() Markus Elfring
2023-03-25  8:32   ` [cocci] [PATCH resent] " Markus Elfring
2023-03-23 17:30 ` [cocci] [PATCH] mm/mempolicy: Fix exception handling in shared_policy_replace() Markus Elfring
2023-03-24 17:30   ` Vlastimil Babka
2023-03-24 18:03     ` Markus Elfring
2023-03-23 21:12 ` [cocci] [PATCH] perf cputopo: Improve exception handling in build_cpu_topology() Markus Elfring
2023-03-25  8:50   ` [cocci] [PATCH resent] " Markus Elfring
2023-03-24 11:43 ` [cocci] [PATCH] perf pmu: Improve exception handling in pmu_lookup() Markus Elfring
2023-03-24 14:12 ` [cocci] [PATCH] selftests/bpf: Improve exception handling in rbtree_add_and_remove() Markus Elfring
     [not found] ` <e6656c83-ee7a-a253-2028-109138779c94@web.de>
2023-03-24 15:42   ` [cocci] [PATCH resent] drm/amd/display: Fix exception handling in dm_validate_stream_and_context() Markus Elfring
     [not found]     ` <32674bac-92c2-8fc7-0977-6d2d81b3257f@amd.com>
2023-03-24 18:19       ` Markus Elfring
     [not found] ` <7214c986-4d0e-ad78-6312-c84515dc9abf@web.de>
2023-03-24 17:02   ` [cocci] [PATCH resent] ext4: Fix exception handling in parse_apply_sb_mount_options() Markus Elfring
     [not found] ` <e33f264a-7ee9-4ebc-d58e-bbb7fd567198@web.de>
2023-03-25  9:31   ` [cocci] [PATCH resent] bcache: Fix exception handling in mca_alloc() Markus Elfring
     [not found]     ` <157b8db9-82f7-85e7-3bbd-7ef3a1797892@suse.de>
2023-03-25 12:21       ` [cocci] [PATCH v2] " Markus Elfring
     [not found]         ` <BE6CEE57-E9AF-4F17-B281-1E00C5DC2A9C@suse.de>
2023-03-25 17:10           ` [cocci] " Markus Elfring
2023-03-25 12:50       ` [cocci] [PATCH resent] " Markus Elfring
     [not found] ` <00589154-00ac-4ed5-2a37-60b3c6f6c523@web.de>
2023-03-25  9:40   ` [cocci] [PATCH resent] mei: Fix exception handling in mei_cl_irq_read_msg() Markus Elfring
     [not found] ` <3675f707-bff0-3caf-29a2-b99e5b9c6554@web.de>
2023-03-25  9:43   ` [cocci] [PATCH resent] mtd: cfi_cmdset_0001: Fix exception handling in cfi_intelext_setup() Markus Elfring
     [not found] ` <21e58abb-f215-b9b7-ffe8-236dd40c6bd2@web.de>
2023-03-25  9:50   ` [cocci] [PATCH resent] bbc_i2c: Fix exception handling in attach_one_i2c() Markus Elfring
     [not found] ` <15fa53e5-916f-dac8-87fb-9cb81021418c@web.de>
2023-03-25 10:20   ` [cocci] [PATCH resent] irqchip/partitions: Fix exception handling in partition_create_desc() Markus Elfring
     [not found] ` <eaa9f90f-c91b-dc87-51a1-d97f99fc5b4b@web.de>
2023-03-25 14:00   ` [cocci] [PATCH resent] dmaengine: bestcomm: Fix exception handling in bcom_task_alloc() Markus Elfring
     [not found] ` <b3cce5b3-2e68-180c-c293-74d4d9d4032c@web.de>
2023-03-25 14:02   ` [cocci] [PATCH resent] cpufreq: sparc: Fix exception handling in two functions Markus Elfring
     [not found]     ` <20230403033529.x6n3ihhkypwizq3b@vireshk-i7>
2023-04-03 12:50       ` [cocci] [PATCH] " Markus Elfring
     [not found]         ` <20230403230432.xeubpa3cc2gt4mw3@vireshk-i7>
2023-04-07 17:48           ` [cocci] [PATCH v2] " Markus Elfring
     [not found]             ` <20230409235511.7xxqdxsqtflrhifk@vireshk-i7>
2023-04-10 13:08               ` [cocci] [v2] " Markus Elfring
     [not found]                 ` <20230411033048.zwsijlyiksjcmgcc@vireshk-i7>
2023-04-11  6:15                   ` Markus Elfring
     [not found]                     ` <20230411064051.qyioheeoectj2lv3@vireshk-i7>
2023-04-11 14:20                       ` Markus Elfring
     [not found] ` <5ed1bc78-77a1-8eb8-43f9-6005d7de49c8@web.de>
2023-03-25 14:05   ` [cocci] [PATCH resent] clk: at91: sama7g5: Add two jump labels in sama7g5_pmc_setup() Markus Elfring
     [not found]     ` <7890284f-5809-2f46-9d5f-52e20a3ec327@microchip.com>
2023-03-28 19:24       ` Markus Elfring
     [not found] ` <8d193937-532f-959f-9b84-d911984508aa@web.de>
2023-03-25 14:07   ` [cocci] [PATCH resent] drbd: Fix exception handling in nla_put_drbd_cfg_context() Markus Elfring
2023-03-27 12:28     ` Christoph Böhmwalder
2023-03-27 17:26       ` [cocci] " Markus Elfring
     [not found] ` <3151f1ef-63c6-d016-7c6a-2572e3d93d8f@web.de>
2023-03-25 14:10   ` [cocci] [PATCH resent] blk-mq: Add two labels in blk_rq_prep_clone() Markus Elfring
     [not found] ` <ab860edf-79ca-2035-c5a3-d25be6fd9dac@web.de>
2023-03-25 14:15   ` [cocci] [PATCH resent] perf/x86/amd/uncore: Fix exception handling in amd_uncore_cpu_up_prepare() Markus Elfring
     [not found]     ` <d691d740-c172-a5cb-e4f0-5bc5687c8464@intel.com>
2023-03-27 17:36       ` [cocci] " Markus Elfring
2023-03-25 18:30 ` [cocci] [PATCH] selftests: cgroup: Fix exception handling in test_memcg_oom_group_score_events() Markus Elfring
     [not found]   ` <fffcd98a-bb73-41cd-8545-0f2c55dd38f9@lucifer.local>
2023-03-26  8:15     ` Markus Elfring [this message]
     [not found]       ` <20230326213900.GJ363182@maniforge>
2023-03-27  5:56         ` Markus Elfring
2023-03-26  8:20 ` [cocci] [PATCH] selinux: Improve exception handling in security_get_bools() Markus Elfring
     [not found]   ` <tencent_1C472DFEAAEC903262297C9B9C978B365909@qq.com>
2023-03-27  5:25     ` [cocci] " Markus Elfring
2023-03-27  7:00   ` [cocci] [PATCH v2] selinux: Adjust implementation of security_get_bools() Markus Elfring
     [not found]     ` <CAHC9VhR=yK72JXW3hJR+gUQtGCNpF0Bzk5RDzPZR0MunC84AUQ@mail.gmail.com>
     [not found]       ` <CAHC9VhREfdgiCji=uEeCrc4w1kPGfnWGKnJuUYKXwTApdneSjQ@mail.gmail.com>
2023-03-28  7:30         ` [cocci] " Markus Elfring
     [not found]           ` <CAHC9VhQfiNd_4uWBmKCC81UnOJb7Y=UFCDMXuqz3=UPr8QtqNw@mail.gmail.com>
2023-03-29  5:20             ` Markus Elfring
2023-04-04  8:00 ` [cocci] Reconsidering repeated checks for error pointers (with SmPL) Markus Elfring
2023-04-05 17:10   ` [cocci] [PATCH] drm/nouveau: Add a jump label in nouveau_gem_ioctl_pushbuf() Markus Elfring
2023-04-05 20:10   ` [cocci] [PATCH] firmware: ti_sci: Fix exception handling in ti_sci_probe() Markus Elfring
     [not found]     ` <20230516152043.bq2hnessstrhbc6s@distort>
2023-05-16 15:56       ` [cocci] " Markus Elfring
2023-04-06 16:10   ` [cocci] [PATCH 0/2] IB/uverbs: Adjustments for create_qp() Markus Elfring
2023-04-06 16:14     ` [cocci] [PATCH 1/2] IB/uverbs: Improve exception handling in create_qp() Markus Elfring
2023-04-06 16:18     ` [cocci] [PATCH 2/2] IB/uverbs: Delete a duplicate check " Markus Elfring
2023-04-06 20:12   ` [cocci] [PATCH] remoteproc: imx_dsp_rproc: Improve exception handling in imx_dsp_rproc_mbox_alloc() Markus Elfring
2023-04-07  6:22   ` [cocci] [PATCH] spi: atmel: Improve exception handling in atmel_spi_configure_dma() Markus Elfring
     [not found]     ` <e3e704f5-3719-637a-8bc5-3a24e2e7cb92@microchip.com>
2023-04-07 15:07       ` Markus Elfring
2023-04-07  7:50   ` [cocci] [PATCH] ipvs: Fix exception handling in two functions Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b7921c9-ee5d-c372-b19b-2701bcf33148@web.de \
    --to=markus.elfring@web.de \
    --cc=cgroups@vger.kernel.org \
    --cc=cocci@inria.fr \
    --cc=hannes@cmpxchg.org \
    --cc=jgkamat@fb.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizefan.x@bytedance.com \
    --cc=lstoakes@gmail.com \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeelb@google.com \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).