From nobody Thu Dec 18 18:01:30 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 893DE127E31 for ; Tue, 30 Apr 2024 09:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714469681; cv=none; b=JsRtVnXyywtX0zTx/v/Q4DdyWK2xgAnOSBU8SPmodIc9cRPc3Dt9nbdgsEknz9RovjJRHBobGIXwX/D7wjTjyIm0KPGT2H2HEIxC1OlkBuwX35/AicfkvJdC5tu6NoP1PM1LwdB70P/huM/Wjq/lNmafr/vcAm4m1/YZdM/znQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714469681; c=relaxed/simple; bh=NM7ltXVgJiTvHbyePJW9hEoscG9RrRRi+f9vhsUXWrA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=E5KbpJDs5XqA5bPyIe4bXzcRc8ItlF8GSY5YgzccTL8FhfVjgYNonFTcd6ed0zlRJpzU13p653N7OD+lwdLILSRD75ia5OOd/egO6KZevx8FJntjJYzglWNmEq0+NeY1nvZQZTwLyxcv64+NuC44C3yE9GpIjPr0y2a4T4nciDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VTFLT27P8zXnlG for ; Tue, 30 Apr 2024 17:30:57 +0800 (CST) Received: from kwepemi500008.china.huawei.com (unknown [7.221.188.139]) by mail.maildlp.com (Postfix) with ESMTPS id C2C5C18007C for ; Tue, 30 Apr 2024 17:34:35 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 30 Apr 2024 17:34:35 +0800 From: Jinjie Ruan To: , CC: Subject: [PATCH] genirq/irqdomain: Clean code for __irq_domain_create() Date: Tue, 30 Apr 2024 17:33:53 +0800 Message-ID: <20240430093353.1919862-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) Content-Type: text/plain; charset="utf-8" Introduce irq_domain_alloc_name() function to handle name allocation for the irq domain, add "out_free_domain" label to free the irq domain, and when "is_fwnode_irqchip(fwnode)" is true, "domain->fwnode =3D fwnode" is the common action, so do it outside the switch, which can make the code more clearer. Signed-off-by: Jinjie Ruan --- kernel/irq/irqdomain.c | 75 +++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 3dd1c871e091..49a983161340 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -127,6 +127,39 @@ void irq_domain_free_fwnode(struct fwnode_handle *fwno= de) } EXPORT_SYMBOL_GPL(irq_domain_free_fwnode); =20 +static int irq_domain_alloc_name(struct fwnode_handle *fwnode, + struct irq_domain *domain, + int unknown_domains, char *in_name) +{ + char *name; + + if (fwnode =3D=3D NULL) { + if (unknown_domains) + domain->name =3D kasprintf(GFP_KERNEL, "unknown-%d", + unknown_domains); + else + domain->name =3D kstrdup(in_name, GFP_KERNEL); + if (!domain->name) + return -ENOMEM; + goto out; + } + + /* + * fwnode paths contain '/', which debugfs is legitimately + * unhappy about. Replace them with ':', which does + * the trick and is not as offensive as '\'... + */ + name =3D kasprintf(GFP_KERNEL, "%pfw", fwnode); + if (!name) + return -ENOMEM; + + domain->name =3D strreplace(name, '/', ':'); + +out: + domain->flags |=3D IRQ_DOMAIN_NAME_ALLOCATED; + return 0; +} + static struct irq_domain *__irq_domain_create(struct fwnode_handle *fwnode, unsigned int size, irq_hw_number_t hwirq_max, @@ -151,53 +184,31 @@ static struct irq_domain *__irq_domain_create(struct = fwnode_handle *fwnode, =20 if (is_fwnode_irqchip(fwnode)) { fwid =3D container_of(fwnode, struct irqchip_fwid, fwnode); + domain->fwnode =3D fwnode; =20 switch (fwid->type) { case IRQCHIP_FWNODE_NAMED: case IRQCHIP_FWNODE_NAMED_ID: - domain->fwnode =3D fwnode; - domain->name =3D kstrdup(fwid->name, GFP_KERNEL); - if (!domain->name) { - kfree(domain); - return NULL; - } - domain->flags |=3D IRQ_DOMAIN_NAME_ALLOCATED; + if (irq_domain_alloc_name(NULL, domain, 0, fwid->name)) + goto out_free_domain; break; default: - domain->fwnode =3D fwnode; domain->name =3D fwid->name; break; } } else if (is_of_node(fwnode) || is_acpi_device_node(fwnode) || is_software_node(fwnode)) { - char *name; - - /* - * fwnode paths contain '/', which debugfs is legitimately - * unhappy about. Replace them with ':', which does - * the trick and is not as offensive as '\'... - */ - name =3D kasprintf(GFP_KERNEL, "%pfw", fwnode); - if (!name) { - kfree(domain); - return NULL; - } - - domain->name =3D strreplace(name, '/', ':'); + if (irq_domain_alloc_name(fwnode, domain, 0, NULL)) + goto out_free_domain; domain->fwnode =3D fwnode; - domain->flags |=3D IRQ_DOMAIN_NAME_ALLOCATED; } =20 if (!domain->name) { if (fwnode) pr_err("Invalid fwnode type for irqdomain\n"); - domain->name =3D kasprintf(GFP_KERNEL, "unknown-%d", - atomic_inc_return(&unknown_domains)); - if (!domain->name) { - kfree(domain); - return NULL; - } - domain->flags |=3D IRQ_DOMAIN_NAME_ALLOCATED; + if (irq_domain_alloc_name(NULL, domain, + atomic_inc_return(&unknown_domains), NULL)) + goto out_free_domain; } =20 fwnode_handle_get(fwnode); @@ -228,6 +239,10 @@ static struct irq_domain *__irq_domain_create(struct f= wnode_handle *fwnode, irq_domain_check_hierarchy(domain); =20 return domain; + +out_free_domain: + kfree(domain); + return NULL; } =20 static void __irq_domain_publish(struct irq_domain *domain) --=20 2.34.1