Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6604814rwp; Tue, 18 Jul 2023 03:09:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlHhzbgjJfcIR4O+IKXpLcfXS5fyyZenAcMreRfIOMqVu4HYgkdbEvKi9qpvfkOa6OVLoZ61 X-Received: by 2002:a05:6512:308f:b0:4fb:92a9:cbe8 with SMTP id z15-20020a056512308f00b004fb92a9cbe8mr10969069lfd.18.1689674953734; Tue, 18 Jul 2023 03:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689674953; cv=none; d=google.com; s=arc-20160816; b=DfHO7uu+zWCf4klDHA36803EYIuisiatw4p3DgHV7Hk4hupsq8a4/GZfvL66k6oul2 3+wYSxvou4D9Wq5pO5EwxvMo0lra51c4JZiozLGd6si34nRKNbRRQOqBK6sTH4rYUJpr lSPknkzusRHX5Yl0aYfhP+FOd0JHMmbnabGKGw8Ccrzwe6GVXCt2CKqvIvh/TtRxm864 /8tu15PzAtcCvAoqoukS6odcvJ6IWP/RYoZRn+f6pQ/loaB6dNDSOa9RUil65VboR+HD LgTQRIRVJmMvU972d7vJFR02DdpkVGC5zkwKoGn1AT99izlZjNokAFL/FB8QfMs67lCJ Cz6w== 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=qVZFnmqBQuGvBS5WU9UrlJdiuKYbVXL0y6kNUDN5WIg=; fh=EGRoNRtgaiBqdPqwJCj3M9D7jnCUDmzfReXXTqOmf+A=; b=jeJFrUPhH4VoHraKOkScR8sq6Wrs89i8sLBepG/pQxqU2ylOLu7Noh8bOzbDUktXdz nuN83tjyxMLBnpI+TEDHgAFMd2fowNhYy55ypgHPzuMymPOTcerSfZyriLyd7Y4iOT3E 9dYuWWfL/uOYct0t3BuoEVLauALRkZTRggv3f8BOQe2fsWgCQRU7fC1itPueCy4WLBJM ErDFgtfsA2nHtw4notFWQA0UdOoURAqZyB4yJkb1s7tSm0MqssdzpLn1zr1UQ+m4G0PW LWOjRDMFsYFZ+nOTIZt37qVhbdt62pUASZHqD+5dMnJsLyEb/mftS5AURrwYp5m8teK9 GJ4w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a05640200c500b0051e52c20926si1010496edu.275.2023.07.18.03.08.49; Tue, 18 Jul 2023 03:09:13 -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 S231962AbjGRJbF (ORCPT + 99 others); Tue, 18 Jul 2023 05:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbjGRJbA (ORCPT ); Tue, 18 Jul 2023 05:31:00 -0400 Received: from 8.mo563.mail-out.ovh.net (8.mo563.mail-out.ovh.net [46.105.60.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77433AF for ; Tue, 18 Jul 2023 02:30:56 -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 C23AC22C09; Tue, 18 Jul 2023 09:25:39 +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 ; Tue, 18 Jul 2023 09:25:39 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.11]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id 60705201389; Tue, 18 Jul 2023 09:25:39 +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; Tue, 18 Jul 2023 11:25:38 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v11 2/5] leds: provide devm_of_led_get_optional() Date: Tue, 18 Jul 2023 11:25:24 +0200 Message-ID: <20230718092527.37516-3-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230718092527.37516-1-jjhiblot@traphandler.com> References: <20230718092527.37516-1-jjhiblot@traphandler.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: DAG1EX1.emp2.local (172.16.2.1) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 6526560288052951431 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhruddruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehieef X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 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 6dae56b914fe..eb1a8494dc5b 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 50b2f8f153fb..95311c70d95c 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -270,6 +270,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 -- 2.34.1