Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp827438ybm; Wed, 27 May 2020 08:57:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy2WfLWWo269to+3JwIWCZvvKLYu5vYd3jmUeFdy6mdc0NX4hBukeCZ39zvZJrXM14KdjY X-Received: by 2002:a50:f78d:: with SMTP id h13mr2103894edn.238.1590595056879; Wed, 27 May 2020 08:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590595056; cv=none; d=google.com; s=arc-20160816; b=mkDVYpy5Uou87PSbxpELJVMH5T8RetM2xel1xOvn/mq1/Zo/DnfJBw0DjV6ygw1yuQ FvR8naFmzYM5RLJQoCTsiDoMRpbW2cXKH8ELU2XQc7jQ6fuSlzpQC442cLMthYKDv8LH aQiMPuvknL4b5rhvQ/R1ST77boST2lS0yOvzy+EsYPxJWL7hREIL/KPW/E2EE9CkeYai laDj8oLEOUIFNiFO8IRbQJKEQQtyWXOlYIaSgM+un18OGjSmIhZffYRnCzIlaAfCW3s9 rnWTnZABgUkkb5AI8xEAIyhJFZoBjGdZTDaPcyno2cjMGQQUMWATxCUsShveD1I0k4qS IjLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zxT1CUhQy7++N7J2uEuPxuFfU6PCHQ/tHRlkWb3usUM=; b=C+Vl4PwNE7bpQNdaijnT6rSCmlOXaIz7Tjb+YJX3x9qkqammHChUeV3fqYnokfnrMb 0PsRmRYxs6cdOrfut8ZraBSUJS+1Ek+Nn7SXWoJNsqGPhgQ7zkEE7+Luo0kTBOxmkXnG Q7g7QIfoakTgaDuMRf+htHWw7S6WHx+RtxySWY4QU/G5Smds8rwQCtPnfpVLbvl9COXn Q7gQWDOiTpMMb43kUVq8ADDFuGVH0aceijdx/Oe8EdtKW5Qq0cREGVFl1Y+X3dI5olfk TN55JpIX6mm4bzU1KCRMdGIo9KxY+eXIsmitLs1Ft2K3jzPaneyGwC1qulo60za18Nqg xD2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8dfz6ch; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nn23si2189171ejb.330.2020.05.27.08.57.13; Wed, 27 May 2020 08:57:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8dfz6ch; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389190AbgE0O0W (ORCPT + 99 others); Wed, 27 May 2020 10:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389036AbgE0O0V (ORCPT ); Wed, 27 May 2020 10:26:21 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B33DC08C5C1; Wed, 27 May 2020 07:26:21 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id 131so3509481pfv.13; Wed, 27 May 2020 07:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zxT1CUhQy7++N7J2uEuPxuFfU6PCHQ/tHRlkWb3usUM=; b=q8dfz6chvwikpsccikn81Com/PJ9/ujiLNqcTif2E/2FoveZ5+q1k908+cV5Ol4u5N pzIIuASzoed2qsWojrwt4YGsWQlgnD9K46B/VExD/nJ4ABpOBmS0s6dXILeWoFa8Hanh o4V1w4L5FoxbSAPAtQz8K2e4zP42/zQhRQ5fZ1U1QCpeGWMxhlyvpa5mkhrTEQNiFcWq X6kf0H0WaYAJD+OEv1vM33n946Q+I8u0frhaREc809ycZ4JMYjPy54KHNAFX9q9XIDxz kk2K5VYoaQsGSH5GN6D2DDEfEP2FJlDvFurdFkZGfFsS3LSFcFR1TogbEsjuPDrhNBdt s5GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zxT1CUhQy7++N7J2uEuPxuFfU6PCHQ/tHRlkWb3usUM=; b=owZ8H9r/J4H+KgnX3l0uX2WnZD9VgAdJpw4Dp59/Z/GSLIo56/vj4tK6f4IlhY22MN dGbYZYn6378yjrbU4jVEtKqNwsmLM6YbMrcpbgNV2CKepMCp9FYRlaEo1T26cyzAO9OH nkHE+YdKcp9CacBeGX22/yQeB5c4Ky8HCxOYVe1AI6r4SYtXk2GBYSsFYkMvIMCkaD9b pK7idBF4sfy9qEmEDWMei67TPyGtAgbqWf1geHLpK+WjYAkf2JHjmjP2rn6JarkOlNSv 13uX+AunazH/OpWfvbGWq/+5at8+RyUzLYLswBXe3nL3BuEnJtTVBitSX+DbwsAlzqKS annw== X-Gm-Message-State: AOAM5335n4qLCDxYDzEo8LsCfeHVTgJRzl3QrX07FHDVm2Dd6NEUIESH CT8HFfrQHluJYCNaQasZKD4= X-Received: by 2002:a63:9255:: with SMTP id s21mr4197708pgn.363.1590589580622; Wed, 27 May 2020 07:26:20 -0700 (PDT) Received: from localhost ([144.34.194.82]) by smtp.gmail.com with ESMTPSA id 5sm2251982pfp.182.2020.05.27.07.26.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 May 2020 07:26:20 -0700 (PDT) From: Dejin Zheng To: corbet@lwn.net, gregkh@linuxfoundation.org, michal.simek@xilinx.com, wsa+renesas@sang-engineering.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dejin Zheng , Wolfram Sang Subject: [PATCH v3 1/2] drivers: provide devm_platform_request_irq() Date: Wed, 27 May 2020 22:26:10 +0800 Message-Id: <20200527142611.9006-1-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It will call devm_request_irq() after platform_get_irq() function in many drivers, sometimes, it is not right for the error handling of these two functions in some drivers. so provide this function to simplify the driver. Cc: Michal Simek Cc: Wolfram Sang Signed-off-by: Dejin Zheng --- v2 -> v3: - add devm_platform_request_irq() to devres.rst by Grygorii's suggestion. v1 -> v2: - The patch content has not changed. just resend it by this discussion: https://patchwork.ozlabs.org/project/linux-i2c/patch/20200520144821.8069-1-zhengdejin5@gmail.com/ .../driver-api/driver-model/devres.rst | 1 + drivers/base/platform.c | 33 +++++++++++++++++++ include/linux/platform_device.h | 4 +++ 3 files changed, 38 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 644078332354..89681264ee2c 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -325,6 +325,7 @@ IRQ devm_request_any_context_irq() devm_request_irq() devm_request_threaded_irq() + devm_platform_request_irq() devm_irq_alloc_descs() devm_irq_alloc_desc() devm_irq_alloc_desc_at() diff --git a/drivers/base/platform.c b/drivers/base/platform.c index c0d0a5490ac6..1d2fd1ea3bc5 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -275,6 +275,39 @@ int platform_irq_count(struct platform_device *dev) } EXPORT_SYMBOL_GPL(platform_irq_count); +/** + * devm_platform_request_irq - get an irq and allocate an interrupt + * line for a managed device + * @pdev: platform device + * @num: IRQ number index + * @irq: get an IRQ for a device if irq != NULL + * @handler: function to be called when the IRQ occurs + * @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 + * + * Return: zero on success, negative error number on failure. + */ +int devm_platform_request_irq(struct platform_device *pdev, unsigned int num, + unsigned int *irq, irq_handler_t handler, + unsigned long irqflags, const char *devname, void *dev_id) +{ + int tmp_irq, ret; + + tmp_irq = platform_get_irq(pdev, num); + if (tmp_irq < 0) + return tmp_irq; + + ret = devm_request_irq(&pdev->dev, tmp_irq, handler, irqflags, + devname, dev_id); + if (ret < 0) + dev_err(&pdev->dev, "can't request IRQ\n"); + else if (irq != NULL) + *irq = tmp_irq; + return ret; +} +EXPORT_SYMBOL_GPL(devm_platform_request_irq); + /** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..d94652deea5c 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -11,6 +11,7 @@ #define _PLATFORM_DEVICE_H_ #include +#include #define PLATFORM_DEVID_NONE (-1) #define PLATFORM_DEVID_AUTO (-2) @@ -70,6 +71,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev, extern int platform_get_irq(struct platform_device *, unsigned int); extern int platform_get_irq_optional(struct platform_device *, unsigned int); extern int platform_irq_count(struct platform_device *); +extern int devm_platform_request_irq(struct platform_device *pdev, + unsigned int num, unsigned int *irq, irq_handler_t handler, + unsigned long irqflags, const char *devname, void *dev_id); extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *); -- 2.25.0