From patchwork Mon Jul 3 09:04:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 115235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp383604vqx; Mon, 3 Jul 2023 02:08:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFMlzL+kvwU0tje4KACFEpeViMfA9DXiyUYjN04KQvBd2O533nvfQ93dM+Ri6/2VLSJWJ7l X-Received: by 2002:a17:90b:3706:b0:263:6297:9f73 with SMTP id mg6-20020a17090b370600b0026362979f73mr11353375pjb.1.1688375324907; Mon, 03 Jul 2023 02:08:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688375324; cv=pass; d=google.com; s=arc-20160816; b=X9BUQsX24UW1NPZUtChjF1iWfbPtvq0pfcSdqfuimwG2N2X/lVwRf8R304JRV8xCvD RZ7D1DkZRiozoMDaZxVtoRZVzCdAJ7RGAs1yIEowmIUGts+epOAzt7wLt3VFDOieBYGx KeeE2eSEUgh3NJQZ4H+Efooin9vGbTjipfOniYvLBhBnlxJiXMS9O2EtH5R4xB+8HfgO Yb1P5Y0nskLHWiJpnXJKpo+G17sG9EQ649w6bJ+ekI9Z/tKo+Mrl79g0khRpA1UWcuxP +QKod1MPmcBw5iArFy7QUS6uuC/eIK2sWrhlRFkRg5RS3iBLlJCu/05hvdraXLcN0NoH bAeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=csZfkdHrHMpJmVGWyQNG7mFt5Qs5fq/20hx9DDm9Hos=; fh=4un03g5hOgD4vDsakT198ju82L+hg2mJrKi74hj9gEc=; b=efHRkpwf8KKg6d4WVeybGy07urVsN2Qbn50WD9eiA082Bf9+KZSHFzxSjtsCxNZJMJ pLmh9/IE2J2SPgVQ1CCq7eU+gPVUvWmmNQraj0ge/IoENEOaEmDdIDJx7V+V527d8F5c 843qdqpXG9QhD1JeL/+0plKO+oy7L131ccZFp7f5Q4/VVfivyqnYVRlLxurvM4cUsoUf Slv+22yPdVcEhYZDO4DvsHEPYkKB0o0K5XrNcHX5/vRkLSZMQ4018GBpr4c7zRUCxiIA tJNTX2jOnwmRM6LsjA4Cc3sh2tPQAL90I7LFNWFrvhy+PenAVR7ywtvjWFOUzw5PnzgW qTKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=V3PY19hP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r20-20020a6560d4000000b00545072f800fsi8481963pgv.320.2023.07.03.02.08.30; Mon, 03 Jul 2023 02:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=V3PY19hP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjGCJFY (ORCPT + 99 others); Mon, 3 Jul 2023 05:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbjGCJFR (ORCPT ); Mon, 3 Jul 2023 05:05:17 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2114.outbound.protection.outlook.com [40.107.117.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DEFEE43; Mon, 3 Jul 2023 02:05:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GFLleYF0J0R6KacPulnEj3+MtwbMNuQWdn+BcosqFoyGuW5aXANVtwTmANPfJ7TDQu9d34QcaBsM0V+AwggnYfGToX1yfFl6L7TWIXsA5jIMr6Z9MnyEYkr5xd8Z9NHjSsi8iJSQ6e+2p7q3YPjGoAun8l5faJarsMx7Y6xXOUIECllPZcPE5c5xQ4CQv2d6yVwSGS8nk+tyOm4RLm7ztNych0RZELg2lKSwWvToS7Zb9wm1e19KD2K0syZB/e8fjr5XeSFmOEYwi57YWp56PadKVNF3SGK8aoySYS+JtWQFese7FYFvWO6PeOgOdZy9MvvhMu1+7W7JAoKhXlt/xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=csZfkdHrHMpJmVGWyQNG7mFt5Qs5fq/20hx9DDm9Hos=; b=b06mgmvs0d1B/itJONZ3SFR5SZZNYh+IRk2c3BVDD8mqc1OpPonIqtNs7xlTBKy7jkiYI8TyQSthf0oiKmmx/lZVagNrMHV18eLy8h1ONSU5sZ0aCrHVJGFyrOgyzB3/cGKDD7v/P6BtYVXwXPzNubANJrSJXcbG+GUUmxrl9WntRM1LMlhcBuO2dBEV7Tfhlpr6so+dLazOgJGpbEnpT5vcf3wIkZX457ANfB9ZOseEApZej8nS+Rrqpiki+g2S/Tlwz7LhRVAvHTC7yPCKCiGKBOWXLqS2E43X4VWrSJw9/2nNvFZCu4/QvlZ8+G+0g4DyIC207Xl9VuZYHpVFQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=csZfkdHrHMpJmVGWyQNG7mFt5Qs5fq/20hx9DDm9Hos=; b=V3PY19hP5/bhwLyHu7GKQRiVGe7O7VZKIE0DzojWb7BiZYDtAhTyQHvIOFD8smRbzYJR0h68O3n28KyS6ZCWgYF748fi4eOddiExNv6zITWzCkjHBiR4JLOnjjTl0LdYdc/9x3QDEuqIh4RyBHn0bCT2aQdE6RFgxcfdS63zVyfX5XX7vJsVfFXFjdmDEZ3o2FDABnOT4OKV/6HFNRwxyOmtu/LtvHT3aRVX+mxrsNxfEQXEeiKZ8HZmYrczG0U4vr1kNlSdrfPMD2dYKcqUYN2plFZwR+gK0PnvNoHa0Xm+y3Swm67fLDLX6tqWwF0nf027Ru17L44IxhPZLQRYsw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by PUZPR06MB5850.apcprd06.prod.outlook.com (2603:1096:301:fa::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 09:05:12 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::fa0e:6c06:7474:285c]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::fa0e:6c06:7474:285c%5]) with mapi id 15.20.6544.024; Mon, 3 Jul 2023 09:05:12 +0000 From: Yangtao Li To: miquel.raynal@bootlin.com, rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, mmayer@broadcom.com, bcm-kernel-feedback-list@broadcom.com, florian.fainelli@broadcom.com, tglx@linutronix.de, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, bchihi@baylibre.com, frank.li@vivo.com, wenst@chromium.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v3 1/5] genirq/devres: Add devm_request_threaded_irq_emsg() Date: Mon, 3 Jul 2023 17:04:50 +0800 Message-Id: <20230703090455.62101-2-frank.li@vivo.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230703090455.62101-1-frank.li@vivo.com> References: <20230703090455.62101-1-frank.li@vivo.com> X-ClientProxiedBy: SI1PR02CA0012.apcprd02.prod.outlook.com (2603:1096:4:1f7::8) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|PUZPR06MB5850:EE_ X-MS-Office365-Filtering-Correlation-Id: 939e675a-b1de-488c-add5-08db7ba49bcb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zYV4QM9pDQWhWsiJzBRz15tR7VpTwoXvFvthBMjbHqZhLQaPjibCtUu+ZMHWzeXghBOlJCGqGSdc4Dt66fXGFcR1tH3oayGNyZY/OP2y6TOt60Mm240ZLSZztk4g/CtjuCnbpZtZQLAbM2XIa3FsJoArIAnA74TvBMPoVc1L95swsDDNis5n4YLYaZ5WClkcEiS0BHDSRaeq0qmqQ1EvmNRkRDltNVz0M/S/zRwUGn17Lz00dBjcFhnHzJ96zouwaWYBIErtcSAUOV3ZTuAN2/9Bc84CkIAiqL8Sk9s1W89MB/DJmsPt+ukOLGVwddNGZv3E9sZdmXNENsOzBvExnQBQdaAmwSoOdOGqkznHvyq/Q/isXgAuA9MTJsvZprxVObjZP+xVbLkGfqFOANVvTp4A8aKb23FROpqp9ngSRlaWNN3VONyD5gy+2BZdWxLkNeWJhnrkp9wv8TQEpdCXGP/QYo4WE8eo6qxutD6GIsT9SQ2oI/JturMOylvky0EuUIqKT15qUjqvcgPOwWgKWXUCiUg4Pcnjn8jWi7jcAJZjdLA8beATYIhZnDczDWkfa3zJJ9qxPa1iVL6JYIz/DPCXwDPu4lNRFb84ztqpi82Gw/CjKVGK1lOXDeQvTMZ/oV/uFgs7px4GK65+Uh6Yxw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(366004)(136003)(39860400002)(346002)(451199021)(2906002)(41300700001)(5660300002)(8676002)(8936002)(7416002)(36756003)(86362001)(186003)(2616005)(478600001)(26005)(6512007)(6506007)(1076003)(6666004)(6486002)(52116002)(316002)(4326008)(66476007)(66556008)(66946007)(38100700002)(38350700002)(921005)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3WQpwtzEUhJ5nTx4Tzokn7G0fG0fFLRYuauXFCfQ+zRwOKQGZoZANU+/GuAtInLW7JPkCHq2Org8JEJd3vdUvNlMCrbjJuPQSVGx0w355MjKgHc/noMlBSoC4S4vgMleQ+dh9n3IycqRrjk/d07Ad9X53yowmUXmEVPEK8m4eeosWhto8Enqo/JFpmNI3RD/HbrBrBnF6WMBf+cqEx2FUZNY3M+yXGLmVKigpZduP+/V8kxN8RAMPDziGcadqfrIx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BifvvS05ZvcjuaS/lf2pr7MJEcX1W3pM+zlxHdhk6iljmuh7LL+W8VS+uFHdrKTGxfpnmr1+10rS7a3Cw+k0Kz7+DT2rNWGGpiHWY10tiqpq6HMvYe++WKfrr3SrqqxMNSTiBrNfyGieGAUPiPwEK1EPXO4ijCihs9tjMjSvBs6N4hZzBujIhcp1fc/VzR9O1Q3kMmC6iSsiQL76Wwz0ze2oMCe19RGt7IJwyOFiy+I2Me1uUsB28rjE720sx X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 939e675a-b1de-488c-add5-08db7ba49bcb X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 09:05:12.5184 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 32c+wNU9o3xR85LqHZFsLg4P0BXzvlk84uVlv45dzVUAAXx8lG0p5zJblo1Zzo+eKmRFR6XUaTcI6C3v97TWmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5850 X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770389844886653311?= X-GMAIL-MSGID: =?utf-8?q?1770389844886653311?= There are more than 700 calls to the devm_request_threaded_irq method. Most drivers only request one interrupt resource, and these error messages are basically the same. If error messages are printed everywhere, more than 1000 lines of code can be saved by removing the msg in the driver. And tglx point out that: If we actually look at the call sites of devm_request_threaded_irq() then the vast majority of them print more or less lousy error messages. A quick grep/sed/awk/sort/uniq revealed 519 messages total (there are probably more) 352 unique messages 323 unique messages after lower casing Those 323 are mostly just variants of the same patterns with slight modifications in formatting and information provided. 186 of these messages do not deliver any useful information, e.g. "no irq", " The most useful one of all is: "could request wakeup irq: %d" So there is certainly an argument to be made that this particular function should print a well formatted and informative error message. It's not a general allocator like kmalloc(). It's specialized and in the vast majority of cases failing to request the interrupt causes the device probe to fail. So having proper and consistent information why the device cannot be used _is_ useful. So add devm_request_threaded_irq_emsg(), which ensure that all error handling branches print error information. In this way, when this function fails, the upper-layer functions can directly return an error code without missing debugging information. Otherwise, the error message will be printed redundantly or missing. Cc: Thomas Gleixner Signed-off-by: Yangtao Li --- include/linux/interrupt.h | 6 ++++++ kernel/irq/devres.c | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index a92bce40b04b..cde034006e3e 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -201,6 +201,12 @@ extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id); struct device; +extern int __must_check +devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq, + irq_handler_t handler, irq_handler_t thread_fn, + unsigned long irqflags, const char *devname, + void *dev_id, const char *emsg); + extern int __must_check devm_request_threaded_irq(struct device *dev, unsigned int irq, irq_handler_t handler, irq_handler_t thread_fn, diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c index f6e5515ee077..f2e669ccd5d4 100644 --- a/kernel/irq/devres.c +++ b/kernel/irq/devres.c @@ -79,6 +79,48 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq, } EXPORT_SYMBOL(devm_request_threaded_irq); +/** + * devm_request_threaded_irq_emsg - allocate an interrupt line for a managed device + * @dev: device to request interrupt for + * @irq: Interrupt line to allocate + * @handler: Function to be called when the IRQ occurs + * @thread_fn: function to be called in a threaded interrupt context. NULL + * for devices which handle everything in @handler + * @irqflags: Interrupt type flags + * @devname: An ascii name for the claiming device, dev_name(dev) if NULL + * @dev_id: A cookie passed back to the handler function + * @emsg: Optional additional error log + * + * This is a variant of the devm_request_threaded_irq function. + * It will print an error message by default when the request fails, + * and the consumer can add a special error msg. + * + * Except for the extra @dev argument, this function takes the + * same arguments and performs the same function as + * request_threaded_irq(). IRQs requested with this function will be + * automatically freed on driver detach. + * + * If an IRQ allocated with this function needs to be freed + * separately, devm_free_irq() must be used. + */ +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq, + irq_handler_t handler, irq_handler_t thread_fn, + unsigned long irqflags, const char *devname, + void *dev_id, const char *emsg) +{ + int rc; + + rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, + devname, dev_id); + if (rc && rc != -EPROBE_DEFER) { + dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n", + thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev), + emsg ? : "", ERR_PTR(rc)); + } + return rc; +} +EXPORT_SYMBOL(devm_request_threaded_irq_emsg); + /** * devm_request_any_context_irq - allocate an interrupt line for a managed device * @dev: device to request interrupt for