Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1899138lqa; Tue, 30 Apr 2024 02:34:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3XWaKoviA6l8tNAcfjoaToIprMp8OF9MI+XTMlV16qQSliEotN6a8XnRWTTKfz4BJ4g+dMJMcD4E1qTCb9J1FsRIE5LuSucEfOY8xoQ== X-Google-Smtp-Source: AGHT+IEFwq+KY10arD7PwC13IR4TTB7WAhTWYq7YDg+JqCur5kFhUZDD4azEhESBFS0QdKLRUOED X-Received: by 2002:a05:6214:124:b0:6a0:a98a:4881 with SMTP id w4-20020a056214012400b006a0a98a4881mr10044937qvs.21.1714469692781; Tue, 30 Apr 2024 02:34:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714469692; cv=pass; d=google.com; s=arc-20160816; b=DuevlHkNfZ98KSPAUPwoIfXSpbi0jcjXH1zLyADiwDLfqS3ki2UP0xdacc95ppnOar aZpbG4kqTFyL26Kx3Ucd/oiAA+nMc1JnLvnJwV/y7nWoEn9cIoVUmf/bKC6ymoP0fVrd A0VwtJAJePpWdb+89E8LFoNkHcM6gCyh+QYACKwthXm3aKHJFF/l43Dy/tNbLfm2k3pt tKv4z28tdEVzvxoMhA9ttrgOw3TZXu2+y0sm4UJKdJKIz64qSMKcktR9TA4n4567lbCB fqfm8vVqj/aUB3WeWM1J33NJn4sWfvYFi//o6zR0xxPHivrBICO1F5IhQoSOyUztfSZn 1zKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=/HgbPKR3Q/QVe1Re7dp2Z2MFOrNYzyXe7OXrsKEk+cI=; fh=iQIEIpegfxGHAXzmCmQbfua7u3pb28YTuJpmY/Z0V14=; b=kWaAS84Lub/mTtRB8FoaT+bTeqqsZt60Vtnfn+A/eeJiAJ22njMNCVe1dKHUu46Kwo N5NdSC56r6OplfrUCaagLuAu0pGSz2vXWIWXHK8Wx8qE3WgeGxSo7zOCzpM25n4/fF+v lYn1ctmYJRZEZJkW5nHUWeyMeZcV1pahu/aN6RrIQ87Ux7NrEWW53cHd7dzO1XfoXBaQ ixmN4BgGz9nILF1MgHAKARGrGhnem7Rvo/lt5hiUpTSatuTLz7UViS68WIaFF4WGqKT+ 01ALErT+dBIUFdAdF6Fw/bHrY8wh1BSm/jXFe060YVpcQQqjO/64olBP6vLgXHrflXGi +uhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-163697-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ha13-20020a05622a2b0d00b0043762e136c0si25930564qtb.542.2024.04.30.02.34.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 02:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163697-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-163697-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 727B51C22297 for ; Tue, 30 Apr 2024 09:34:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A32771292CE; Tue, 30 Apr 2024 09:34:41 +0000 (UTC) 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: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) 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 = 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 *fwnode) } EXPORT_SYMBOL_GPL(irq_domain_free_fwnode); +static int irq_domain_alloc_name(struct fwnode_handle *fwnode, + struct irq_domain *domain, + int unknown_domains, char *in_name) +{ + char *name; + + if (fwnode == NULL) { + if (unknown_domains) + domain->name = kasprintf(GFP_KERNEL, "unknown-%d", + unknown_domains); + else + domain->name = 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 = kasprintf(GFP_KERNEL, "%pfw", fwnode); + if (!name) + return -ENOMEM; + + domain->name = strreplace(name, '/', ':'); + +out: + domain->flags |= 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, if (is_fwnode_irqchip(fwnode)) { fwid = container_of(fwnode, struct irqchip_fwid, fwnode); + domain->fwnode = fwnode; switch (fwid->type) { case IRQCHIP_FWNODE_NAMED: case IRQCHIP_FWNODE_NAMED_ID: - domain->fwnode = fwnode; - domain->name = kstrdup(fwid->name, GFP_KERNEL); - if (!domain->name) { - kfree(domain); - return NULL; - } - domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; + if (irq_domain_alloc_name(NULL, domain, 0, fwid->name)) + goto out_free_domain; break; default: - domain->fwnode = fwnode; domain->name = 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 = kasprintf(GFP_KERNEL, "%pfw", fwnode); - if (!name) { - kfree(domain); - return NULL; - } - - domain->name = strreplace(name, '/', ':'); + if (irq_domain_alloc_name(fwnode, domain, 0, NULL)) + goto out_free_domain; domain->fwnode = fwnode; - domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; } if (!domain->name) { if (fwnode) pr_err("Invalid fwnode type for irqdomain\n"); - domain->name = kasprintf(GFP_KERNEL, "unknown-%d", - atomic_inc_return(&unknown_domains)); - if (!domain->name) { - kfree(domain); - return NULL; - } - domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; + if (irq_domain_alloc_name(NULL, domain, + atomic_inc_return(&unknown_domains), NULL)) + goto out_free_domain; } fwnode_handle_get(fwnode); @@ -228,6 +239,10 @@ static struct irq_domain *__irq_domain_create(struct fwnode_handle *fwnode, irq_domain_check_hierarchy(domain); return domain; + +out_free_domain: + kfree(domain); + return NULL; } static void __irq_domain_publish(struct irq_domain *domain) -- 2.34.1