From patchwork Fri Jul 28 15:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 127736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp555665vqg; Fri, 28 Jul 2023 09:36:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEiI9JUpMeKu3EpLmXHvWleQZXpprfFxuj+VXKPzkcu7azufK3Yoh3WzoEuu7SvJ+AW0O1O X-Received: by 2002:a17:907:2cf8:b0:994:1844:549c with SMTP id hz24-20020a1709072cf800b009941844549cmr2505568ejc.0.1690562174779; Fri, 28 Jul 2023 09:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690562174; cv=none; d=google.com; s=arc-20160816; b=xS3mV6RAQZvap+c/ijTjj/uMQDTYwqHP1XaQQ4fispW73A2EVFGHJe+zT9vAgE2hW7 aBBoP50hpXYFdyCr7lBaFUa1y76cz4qIZ7JOg+9tyuBD2rogy1IxmC5KQxvvetJMYfWG aox860pk8qDFVlOizsh391QX7iPZmTWkvOrepebfyze3Bc9+Inj7Q82lcjB0uVRv6vht olyYNgR6i09tpMytWCQj6eVjoK659BPrrxnORS5vnKlu46RpXuuKeO8soaWhBCMqtusu QdRxGtgh1TfWwv7M72dZ+pIkKqustjHb36n3lxu0t++llfxd3uvg6MFzm0kSZ0Evk2yR 22rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oITxVBzs4/bivdJ4fpVUBfJzJEaLX4XOVWEoPdU2pgo=; fh=EGRoNRtgaiBqdPqwJCj3M9D7jnCUDmzfReXXTqOmf+A=; b=ot9+d41MbGfEZS9kLwDs92SqAI4TiSr039dW1RUysddDG76vad8VZEDgcIyLoF5nTV v05tHqF6aAYeBM+++dSstRCJhcLh5jhZhxUDIUTkTxrKuT+eoxc+0q67BcCdNDmcT5uh 2CY9TTtVfwgA0F0+dvclfgh63rvpk8shNgMXcjM8StGfo8r1k6BSBEI/ZmHizY/tmKIX sOerA1EtmVUjGHYO/QMT9/FeD47qiYtHLc5lQGziAx0loQJsnfjf14o7mkpOXSliHa3B eNNybq7l4Lore6tQTGC6FZ2rn7pdnskdIW0YdOWem16cpO8wIE2G8/DbJz37VAlYjINW DTxQ== ARC-Authentication-Results: i=1; mx.google.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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t25-20020a1709066bd900b009938899a3besi1998141ejs.211.2023.07.28.09.35.50; Fri, 28 Jul 2023 09:36:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233005AbjG1QQK (ORCPT + 99 others); Fri, 28 Jul 2023 12:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbjG1QQH (ORCPT ); Fri, 28 Jul 2023 12:16:07 -0400 Received: from 1.mo563.mail-out.ovh.net (1.mo563.mail-out.ovh.net [178.33.106.244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DA93AB4 for ; Fri, 28 Jul 2023 09:15:59 -0700 (PDT) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [51.68.80.175]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id 58EA4229C0; Fri, 28 Jul 2023 15:37:43 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net. [127.0.0.1]) by director1.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Fri, 28 Jul 2023 15:37:43 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.11]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id ED9EB2011DD; Fri, 28 Jul 2023 15:37:42 +0000 (UTC) Received: from traphandler.com (88.161.25.233) by DAG1EX1.emp2.local (172.16.2.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 17:37:42 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [RESEND] [PATCH v11 1/4] leds: provide devm_of_led_get_optional() Date: Fri, 28 Jul 2023 17:37:28 +0200 Message-ID: <20230728153731.3742339-2-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728153731.3742339-1-jjhiblot@traphandler.com> References: <20230728153731.3742339-1-jjhiblot@traphandler.com> MIME-Version: 1.0 X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: CAS4.emp2.local (172.16.1.4) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 16196914588195699079 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrieeigdekkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhruddruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehieef X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: INBOX X-GMAIL-THRID: 1772682922831134699 X-GMAIL-MSGID: 1772682922831134699 Add an optional variant of devm_of_led_get(). It behaves the same as devm_of_led_get() except where the LED doesn't exist. In this case, instead of returning -ENOENT, the function returns NULL. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Andy Shevchenko --- drivers/leds/led-class.c | 25 +++++++++++++++++++++++++ include/linux/leds.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 4758da2b59cf..78068b06d009 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -402,6 +402,31 @@ void led_remove_lookup(struct led_lookup_data *led_lookup) } EXPORT_SYMBOL_GPL(led_remove_lookup); +/** + * devm_of_led_get_optional - Resource-managed request of an optional LED device + * @dev: LED consumer + * @index: index of the LED to obtain in the consumer + * + * The device node of the device is parsed to find the requested LED device. + * The LED device returned from this function is automatically released + * on driver detach. + * + * @return a pointer to a LED device, ERR_PTR(errno) on failure and NULL if the + * led was not found. + */ +struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev, + int index) +{ + struct led_classdev *led; + + led = devm_of_led_get(dev, index); + if (IS_ERR(led) && PTR_ERR(led) == -ENOENT) + return NULL; + + return led; +} +EXPORT_SYMBOL_GPL(devm_of_led_get_optional); + static int led_classdev_next_name(const char *init_name, char *name, size_t len) { diff --git a/include/linux/leds.h b/include/linux/leds.h index 7d428100b42b..8740b4e47f88 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -313,6 +313,8 @@ extern struct led_classdev *of_led_get(struct device_node *np, int index); extern void led_put(struct led_classdev *led_cdev); struct led_classdev *__must_check devm_of_led_get(struct device *dev, int index); +struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev, + int index); /** * led_blink_set - set blinking with software fallback