Message ID | 170627361652.398.12825437185563577604.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp635664dyb; Fri, 26 Jan 2024 04:54:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9TdiHRLheQB+j6Z8KPlC8WHmzzxdJTO1WkMGGm+N4EVk5Tu39MVxc9nNJdqkAX6pc2KE+ X-Received: by 2002:a62:cdcd:0:b0:6dd:c69f:5e43 with SMTP id o196-20020a62cdcd000000b006ddc69f5e43mr1032090pfg.2.1706273651278; Fri, 26 Jan 2024 04:54:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706273651; cv=pass; d=google.com; s=arc-20160816; b=sXEqH8KJ2ORuSqMfDCOQw5SzIvTN4mVCLdCXiLPbUsEaMw9XjRDb7rPcojv7hbK9jZ NPRKTqyzyte/lQOoMmSmCi0xWu0UYcPkhUerupAbvWPwNLvTfce5NEf5/YTz7K5kD8Fy fRftj39RRjwlsmGp0WX89lUH82t/UrsioWSNBwffYnkICOnK+F0dXqld0uoYBRvC1S/u /w0N6wjgCZwP9TZZPyjE5ICVQv82Sn1e60z2lp5Q+FwGpIZQ/Z6an3/wV6chSYIaV1aY SOHe+K/8fvb/bcJ9foQGdsVjZLQGGQ69lvwFTQI2Nvt/oj5eC2jGQm3tmtrv481pq2fw eVXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=imNQGpxCfZzxXKHa8c0ZjGv5PSBz4kBsS94bs6102ZY=; fh=qfa+0ZOjO+b611stzTmSeV8Ot1nXXQib35w1dhnlFsk=; b=OMM8ObmVa8yA1wVLH6c4f0+BmIZ0U5B2q0bF8VhDGuMvjUvFPdmQwxnpYM7PMeKj5B PZd/LnBcieJQ4bCviHRFRu0KWy04izyCM0gQOYA5XYg/P4UCGgaBYIPZfqKFAv/aoYI7 bLxnG0LW/KHi8ikD3+7VDMBNH4aPdoU3EPeIKOl9EMhPnspQJ4C+pj5k2+0t3tP5521v tNkVeG6Qt6kHmxJX4IfBdPJrKP7KjOkYVrnkeCT1+26rGdVyK3TMipjzHOdc/9TuVPmS 1TmGuS1qL5QGi+yaUz6NNbXLGyxhywpsg9dHOMy0IF1ayxkYTqL25HqubLs0jyrWVM3E YMPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I8tRvKpc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yMoVsEeE; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k30-20020a63ba1e000000b005c66e60900csi1115303pgf.239.2024.01.26.04.54.11 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 04:54:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I8tRvKpc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yMoVsEeE; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40102-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.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 E2416292A99 for <ouuuleilei@gmail.com>; Fri, 26 Jan 2024 12:54:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0F411B96E; Fri, 26 Jan 2024 12:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I8tRvKpc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yMoVsEeE" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 845E11B7E1; Fri, 26 Jan 2024 12:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273621; cv=none; b=UY9sdOScZ3fsAmjcFVxZ62qpNdEcpe2eVIKM3a7M1TBJGL7JDesLlEKcCxdVuYofvcVATxQTmBb5MU3M/dlB7+zfbsQc1m4W9hIUE+1Duk45Otwn9qLGAPhoTzB9TdBqWnzGKH8+LnrsGNRKqBa6Qmu/tV6iha49h6T2I3OWU9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273621; c=relaxed/simple; bh=iWrPdyaty4Qhj3iNIhG/aBV7WxECmUEMFOQ4WgUrXkI=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=WH1UNf6KTNXSz4Z2Mc9A3/PKMH8MCT1+tXdi8sqL5mje9v8jCH/cd4GJgf4CNbyPD0xA62JIXL5z9oU8sjvArg7+KLQA62vTG/d2ZS/+rB3Ez5wXRKzjG40GfbSt7bOdhQlXkxzxfkLkqYg5iQzp2HrlqmjU0crohw27lAYzlaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I8tRvKpc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yMoVsEeE; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 26 Jan 2024 12:53:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706273617; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=imNQGpxCfZzxXKHa8c0ZjGv5PSBz4kBsS94bs6102ZY=; b=I8tRvKpcA/HG6rl48lTS2e0LIlTiJRRaV6+t0T723nkyrC93YQJRd5tI8R/5B3ibGKHctB xobxpkHaM5pQrHrDTAylIuoefhR7tAk74J+Yd42BT3lXGa5nECfMwDVHt3yPCQZqfhKqte pCaTLE0tvgbcvPmT8FKpgm3+j6ztf41ukPd7mQtr6/5aUulNYIy5SiMiZ4ts7iB/ktExuv 0RA8umgOPWUtPRaW5DscFLsgXi9EBdAUHBKrklIru9iORVWCY8RwLUlA/ZNSmyqcJRFKtM p+PT1iaqe8Mndup19cyfJe6cnR+4rIMmvy5oPzCAgiSpb9r/+nJKBafN8Fn82A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706273617; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=imNQGpxCfZzxXKHa8c0ZjGv5PSBz4kBsS94bs6102ZY=; b=yMoVsEeEMd0WwSWlfhlePUnpEoBYLv/+XpdR0Gz4ibdbKwKBq+Dcb1AzwtVLUhrWo97Ikb cnQlsmIYVOMvjwAw== From: "tip-bot2 for Bartosz Golaszewski" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq/irq_sim: Shrink code by using cleanup helpers Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>, Thomas Gleixner <tglx@linutronix.de>, x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20240122124243.44002-5-brgl@bgdev.pl> References: <20240122124243.44002-5-brgl@bgdev.pl> 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 Message-ID: <170627361652.398.12825437185563577604.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789157600301388909 X-GMAIL-MSGID: 1789157600301388909 |
Series |
[tip:,irq/core] genirq/irq_sim: Shrink code by using cleanup helpers
|
|
Commit Message
tip-bot2 for Thomas Gleixner
Jan. 26, 2024, 12:53 p.m. UTC
The following commit has been merged into the irq/core branch of tip: Commit-ID: 590610d72a790458431cbbebc71ee24521533b5e Gitweb: https://git.kernel.org/tip/590610d72a790458431cbbebc71ee24521533b5e Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> AuthorDate: Mon, 22 Jan 2024 13:42:43 +01:00 Committer: Thomas Gleixner <tglx@linutronix.de> CommitterDate: Fri, 26 Jan 2024 13:44:48 +01:00 genirq/irq_sim: Shrink code by using cleanup helpers Use the new __free() mechanism to remove all gotos and simplify the error paths. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl --- kernel/irq/irq_sim.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
Comments
On Fri, Jan 26, 2024 at 12:53:36PM -0000, tip-bot2 for Bartosz Golaszewski wrote: > The following commit has been merged into the irq/core branch of tip: > > Commit-ID: 590610d72a790458431cbbebc71ee24521533b5e > Gitweb: https://git.kernel.org/tip/590610d72a790458431cbbebc71ee24521533b5e > Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > AuthorDate: Mon, 22 Jan 2024 13:42:43 +01:00 > Committer: Thomas Gleixner <tglx@linutronix.de> > CommitterDate: Fri, 26 Jan 2024 13:44:48 +01:00 > > genirq/irq_sim: Shrink code by using cleanup helpers > > Use the new __free() mechanism to remove all gotos and simplify the error > paths. > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl > > --- > kernel/irq/irq_sim.c | 25 ++++++++++--------------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c > index b0d50b4..fe8fd30 100644 > --- a/kernel/irq/irq_sim.c > +++ b/kernel/irq/irq_sim.c > @@ -4,6 +4,7 @@ > * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com> > */ > > +#include <linux/cleanup.h> > #include <linux/interrupt.h> > #include <linux/irq.h> > #include <linux/irq_sim.h> > @@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = { > struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, > unsigned int num_irqs) > { > - struct irq_sim_work_ctx *work_ctx; > + struct irq_sim_work_ctx *work_ctx __free(kfree) = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > + unsigned long *pending; > > - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > if (!work_ctx) > - goto err_out; > + return ERR_PTR(-ENOMEM); > > - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); > - if (!work_ctx->pending) > - goto err_free_work_ctx; > + pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); Apologies if this has already been reported elsewhere. This does not match what was sent and it causes the build to break with both GCC: In file included from include/linux/compiler_types.h:89, from <command-line>: kernel/irq/irq_sim.c: In function 'irq_domain_create_sim': include/linux/compiler_attributes.h:76:41: error: expected expression before '__attribute__' 76 | #define __cleanup(func) __attribute__((__cleanup__(func))) | ^~~~~~~~~~~~~ include/linux/cleanup.h:64:25: note: in expansion of macro '__cleanup' 64 | #define __free(_name) __cleanup(__free_##_name) | ^~~~~~~~~ kernel/irq/irq_sim.c:173:19: note: in expansion of macro '__free' 173 | pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); | ^~~~~~ and Clang: kernel/irq/irq_sim.c:173:12: error: expected expression 173 | pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); | ^ include/linux/cleanup.h:64:23: note: expanded from macro '__free' 64 | #define __free(_name) __cleanup(__free_##_name) | ^ include/linux/compiler-clang.h:15:25: note: expanded from macro '__cleanup' 15 | #define __cleanup(func) __maybe_unused __attribute__((__cleanup__(func))) | ^ include/linux/compiler_attributes.h:344:41: note: expanded from macro '__maybe_unused' 344 | #define __maybe_unused __attribute__((__unused__)) | ^ 1 error generated. This was initially noticed by our CI: https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/7671789235/job/20915505965 https://storage.tuxsuite.com/public/clangbuiltlinux/continuous-integration2/builds/2bVGKZUmat8fRr582Nh8hNA6FXD/build.log Cheers, Nathan > + if (!pending) > + return ERR_PTR(-ENOMEM); > > work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs, > &irq_sim_domain_ops, > work_ctx); > if (!work_ctx->domain) > - goto err_free_bitmap; > + return ERR_PTR(-ENOMEM); > > work_ctx->irq_count = num_irqs; > work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq); > + work_ctx->pending = no_free_ptr(pending); > > - return work_ctx->domain; > - > -err_free_bitmap: > - bitmap_free(work_ctx->pending); > -err_free_work_ctx: > - kfree(work_ctx); > -err_out: > - return ERR_PTR(-ENOMEM); > + return no_free_ptr(work_ctx)->domain; > } > EXPORT_SYMBOL_GPL(irq_domain_create_sim); >
On Fri, 26 Jan 2024 at 22:05, Nathan Chancellor <nathan@kernel.org> wrote: > > On Fri, Jan 26, 2024 at 12:53:36PM -0000, tip-bot2 for Bartosz Golaszewski wrote: > > The following commit has been merged into the irq/core branch of tip: > > > > Commit-ID: 590610d72a790458431cbbebc71ee24521533b5e > > Gitweb: https://git.kernel.org/tip/590610d72a790458431cbbebc71ee24521533b5e > > Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > AuthorDate: Mon, 22 Jan 2024 13:42:43 +01:00 > > Committer: Thomas Gleixner <tglx@linutronix.de> > > CommitterDate: Fri, 26 Jan 2024 13:44:48 +01:00 > > > > genirq/irq_sim: Shrink code by using cleanup helpers > > > > Use the new __free() mechanism to remove all gotos and simplify the error > > paths. > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > > Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl > > > > --- > > kernel/irq/irq_sim.c | 25 ++++++++++--------------- > > 1 file changed, 10 insertions(+), 15 deletions(-) > > > > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c > > index b0d50b4..fe8fd30 100644 > > --- a/kernel/irq/irq_sim.c > > +++ b/kernel/irq/irq_sim.c > > @@ -4,6 +4,7 @@ > > * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com> > > */ > > > > +#include <linux/cleanup.h> > > #include <linux/interrupt.h> > > #include <linux/irq.h> > > #include <linux/irq_sim.h> > > @@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = { > > struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, > > unsigned int num_irqs) > > { > > - struct irq_sim_work_ctx *work_ctx; > > + struct irq_sim_work_ctx *work_ctx __free(kfree) = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > + unsigned long *pending; > > > > - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > if (!work_ctx) > > - goto err_out; > > + return ERR_PTR(-ENOMEM); > > > > - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); > > - if (!work_ctx->pending) > > - goto err_free_work_ctx; > > + pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); > > Apologies if this has already been reported elsewhere. This does not > match what was sent and it causes the build to break with both GCC: > I did not see any other report. I don't know what happened here but this was a ninja edit as it's not what I sent. If Thomas' intention was to move the variable declaration and detach it from the assignment then 'pending' should at least be set to NULL and __free() must decorate the declaration. But the coding style of declaring variables when they're first assigned their auto-cleaned value is what Linus Torvalds explicitly asked me to do when I first started sending PRs containing uses of linux/cleanup.h. Bartosz > In file included from include/linux/compiler_types.h:89, > from <command-line>: > kernel/irq/irq_sim.c: In function 'irq_domain_create_sim': > include/linux/compiler_attributes.h:76:41: error: expected expression before '__attribute__' > 76 | #define __cleanup(func) __attribute__((__cleanup__(func))) > | ^~~~~~~~~~~~~ > include/linux/cleanup.h:64:25: note: in expansion of macro '__cleanup' > 64 | #define __free(_name) __cleanup(__free_##_name) > | ^~~~~~~~~ > kernel/irq/irq_sim.c:173:19: note: in expansion of macro '__free' > 173 | pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); > | ^~~~~~ > > and Clang: > > kernel/irq/irq_sim.c:173:12: error: expected expression > 173 | pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); > | ^ > include/linux/cleanup.h:64:23: note: expanded from macro '__free' > 64 | #define __free(_name) __cleanup(__free_##_name) > | ^ > include/linux/compiler-clang.h:15:25: note: expanded from macro '__cleanup' > 15 | #define __cleanup(func) __maybe_unused __attribute__((__cleanup__(func))) > | ^ > include/linux/compiler_attributes.h:344:41: note: expanded from macro '__maybe_unused' > 344 | #define __maybe_unused __attribute__((__unused__)) > | ^ > 1 error generated. > > This was initially noticed by our CI: > > https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/7671789235/job/20915505965 > https://storage.tuxsuite.com/public/clangbuiltlinux/continuous-integration2/builds/2bVGKZUmat8fRr582Nh8hNA6FXD/build.log > > Cheers, > Nathan > > > + if (!pending) > > + return ERR_PTR(-ENOMEM); > > > > work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs, > > &irq_sim_domain_ops, > > work_ctx); > > if (!work_ctx->domain) > > - goto err_free_bitmap; > > + return ERR_PTR(-ENOMEM); > > > > work_ctx->irq_count = num_irqs; > > work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq); > > + work_ctx->pending = no_free_ptr(pending); > > > > - return work_ctx->domain; > > - > > -err_free_bitmap: > > - bitmap_free(work_ctx->pending); > > -err_free_work_ctx: > > - kfree(work_ctx); > > -err_out: > > - return ERR_PTR(-ENOMEM); > > + return no_free_ptr(work_ctx)->domain; > > } > > EXPORT_SYMBOL_GPL(irq_domain_create_sim); > >
* Bartosz Golaszewski <bartosz.golaszewski@linaro.org> wrote: > On Fri, 26 Jan 2024 at 22:05, Nathan Chancellor <nathan@kernel.org> wrote: > > > > > Committer: Thomas Gleixner <tglx@linutronix.de> > > > CommitterDate: Fri, 26 Jan 2024 13:44:48 +01:00 > > > > > > genirq/irq_sim: Shrink code by using cleanup helpers > > > > > > Use the new __free() mechanism to remove all gotos and simplify the error > > > paths. > > > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > > > Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl > > > > > > --- > > > kernel/irq/irq_sim.c | 25 ++++++++++--------------- > > > 1 file changed, 10 insertions(+), 15 deletions(-) > > > > > > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c > > > index b0d50b4..fe8fd30 100644 > > > --- a/kernel/irq/irq_sim.c > > > +++ b/kernel/irq/irq_sim.c > > > @@ -4,6 +4,7 @@ > > > * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com> > > > */ > > > > > > +#include <linux/cleanup.h> > > > #include <linux/interrupt.h> > > > #include <linux/irq.h> > > > #include <linux/irq_sim.h> > > > @@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = { > > > struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, > > > unsigned int num_irqs) > > > { > > > - struct irq_sim_work_ctx *work_ctx; > > > + struct irq_sim_work_ctx *work_ctx __free(kfree) = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > > + unsigned long *pending; > > > > > > - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > > if (!work_ctx) > > > - goto err_out; > > > + return ERR_PTR(-ENOMEM); > > > > > > - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); > > > - if (!work_ctx->pending) > > > - goto err_free_work_ctx; > > > + pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); > > > > Apologies if this has already been reported elsewhere. This does not > > match what was sent and it causes the build to break with both GCC: > > > > I did not see any other report. I don't know what happened here but > this was a ninja edit as it's not what I sent. If Thomas' intention > was to move the variable declaration and detach it from the assignment > then 'pending' should at least be set to NULL and __free() must > decorate the declaration. > > But the coding style of declaring variables when they're first > assigned their auto-cleaned value is what Linus Torvalds explicitly > asked me to do when I first started sending PRs containing uses of > linux/cleanup.h. Ok - I've rebased tip:irq/core with the original patch. Do you have a reference to Linus's mail about C++ style definition of variables? I can see the validity of the pattern in this context, but it's explicitly against the kernel coding style AFAICS, which I suppose prompted Thomas's edit. I'd like to have an URL handy when the inevitable checkpatch 'fix' gets submitted. ;-) Thanks, Ingo
On Mon, 29 Jan 2024 at 11:13, Ingo Molnar <mingo@kernel.org> wrote: > > > * Bartosz Golaszewski <bartosz.golaszewski@linaro.org> wrote: > > > On Fri, 26 Jan 2024 at 22:05, Nathan Chancellor <nathan@kernel.org> wrote: > > > > > > > Committer: Thomas Gleixner <tglx@linutronix.de> > > > > CommitterDate: Fri, 26 Jan 2024 13:44:48 +01:00 > > > > > > > > genirq/irq_sim: Shrink code by using cleanup helpers > > > > > > > > Use the new __free() mechanism to remove all gotos and simplify the error > > > > paths. > > > > > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > > > > Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl > > > > > > > > --- > > > > kernel/irq/irq_sim.c | 25 ++++++++++--------------- > > > > 1 file changed, 10 insertions(+), 15 deletions(-) > > > > > > > > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c > > > > index b0d50b4..fe8fd30 100644 > > > > --- a/kernel/irq/irq_sim.c > > > > +++ b/kernel/irq/irq_sim.c > > > > @@ -4,6 +4,7 @@ > > > > * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com> > > > > */ > > > > > > > > +#include <linux/cleanup.h> > > > > #include <linux/interrupt.h> > > > > #include <linux/irq.h> > > > > #include <linux/irq_sim.h> > > > > @@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = { > > > > struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, > > > > unsigned int num_irqs) > > > > { > > > > - struct irq_sim_work_ctx *work_ctx; > > > > + struct irq_sim_work_ctx *work_ctx __free(kfree) = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > > > + unsigned long *pending; > > > > > > > > - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); > > > > if (!work_ctx) > > > > - goto err_out; > > > > + return ERR_PTR(-ENOMEM); > > > > > > > > - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); > > > > - if (!work_ctx->pending) > > > > - goto err_free_work_ctx; > > > > + pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); > > > > > > Apologies if this has already been reported elsewhere. This does not > > > match what was sent and it causes the build to break with both GCC: > > > > > > > I did not see any other report. I don't know what happened here but > > this was a ninja edit as it's not what I sent. If Thomas' intention > > was to move the variable declaration and detach it from the assignment > > then 'pending' should at least be set to NULL and __free() must > > decorate the declaration. > > > > But the coding style of declaring variables when they're first > > assigned their auto-cleaned value is what Linus Torvalds explicitly > > asked me to do when I first started sending PRs containing uses of > > linux/cleanup.h. > > Ok - I've rebased tip:irq/core with the original patch. > > Do you have a reference to Linus's mail about C++ style definition > of variables? I can see the validity of the pattern in this context, > but it's explicitly against the kernel coding style AFAICS, which > I suppose prompted Thomas's edit. I'd like to have an URL handy when the > inevitable checkpatch 'fix' gets submitted. ;-) > Sure, here's one rant I was the target of: https://lore.kernel.org/all/CAHk-=wgRHiV5VSxtfXA4S6aLUmcQYEuB67u3BJPJPtuESs1JyA@mail.gmail.com/ Bartosz
diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index b0d50b4..fe8fd30 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -4,6 +4,7 @@ * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com> */ +#include <linux/cleanup.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/irq_sim.h> @@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = { struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, unsigned int num_irqs) { - struct irq_sim_work_ctx *work_ctx; + struct irq_sim_work_ctx *work_ctx __free(kfree) = kmalloc(sizeof(*work_ctx), GFP_KERNEL); + unsigned long *pending; - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); if (!work_ctx) - goto err_out; + return ERR_PTR(-ENOMEM); - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); - if (!work_ctx->pending) - goto err_free_work_ctx; + pending = __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); + if (!pending) + return ERR_PTR(-ENOMEM); work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs, &irq_sim_domain_ops, work_ctx); if (!work_ctx->domain) - goto err_free_bitmap; + return ERR_PTR(-ENOMEM); work_ctx->irq_count = num_irqs; work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq); + work_ctx->pending = no_free_ptr(pending); - return work_ctx->domain; - -err_free_bitmap: - bitmap_free(work_ctx->pending); -err_free_work_ctx: - kfree(work_ctx); -err_out: - return ERR_PTR(-ENOMEM); + return no_free_ptr(work_ctx)->domain; } EXPORT_SYMBOL_GPL(irq_domain_create_sim);