Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2731247rwi; Fri, 28 Oct 2022 10:29:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qv5gxXS2mumJxXNko4QReRqzVa74swR0/ExbwTxL345Drd9kf6pYoKY3bX9jQkmnwZzZ/ X-Received: by 2002:a17:906:dc8f:b0:7a5:8160:1995 with SMTP id cs15-20020a170906dc8f00b007a581601995mr423795ejc.500.1666978161859; Fri, 28 Oct 2022 10:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666978161; cv=none; d=google.com; s=arc-20160816; b=skXgBG+1Jb028pI6ZNV5QzoXol53glK3PfWYcIgFVzZUMvQo8TBohthSctNtMl4PvE IdHxkjKzRV5NR/Ys7s73uKIZHwDOaq2zE5vv/R92g7EteTtLxL2KmHjn/eUrf3dlTtFL ZRzDhFYCQqhVT9TnSTqISDX9EyFUskTnyx6n7OwbsZMtHa4ZpMvET34yc5yT/YFpUj4N m4g6TijJxvbn6Ov1lUxcrh45f8tX47ltKrX6t3xEwQ+nlIUbsl1Krmefg+PTDxZZVwLe Ex4HE5eoMMXZy36oyMvyKybDYWasPETuwgiQeRuS6iEbIPzn7PXqkcPoAvU+r/gSi6eJ XoIw== 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=k+id1ddpopq8eTJxLphUTWsaPEQ5G4KemEgbZ4Fa3ss=; b=l7uNIWOzNyOSavpzE90nzFm+2jvskbNQbFqVln3By89Oia2cYhEEvfgeH6PAbs+8JW vQOGbOwoYfPy7sVLRvd7mnFtWAoAJG3dVJsJuZ17Fc2bp1llcJhXIe/InixzcbZyVMEu gt2DcHt2cEF9CYlzfViaWvyA1T+pHTN2Z9KvviBpPBP7yHTY3bRMt8nK9MdCX+qGMe6Q MgQuak2aHJKrhAFo6qEyjNDJi9EEI1alUQJYm4849vvvFeSKH1diNMBmo35X2EHIKX9u TjniXS2rlioseuh6YuAPfIjb69E6iXULq8idbJkqGWURe07+LQuFkxPfBRe6Lb54OmXo 8Pew== 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 fk6-20020a056402398600b0045c3592301dsi2669029edb.191.2022.10.28.10.28.56; Fri, 28 Oct 2022 10:29:21 -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 S230038AbiJ1REy (ORCPT + 99 others); Fri, 28 Oct 2022 13:04:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231272AbiJ1REL (ORCPT ); Fri, 28 Oct 2022 13:04:11 -0400 Received: from smtpout1.mo528.mail-out.ovh.net (smtpout1.mo528.mail-out.ovh.net [46.105.34.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 873B827CF4; Fri, 28 Oct 2022 10:03:27 -0700 (PDT) Received: from pro2.mail.ovh.net (unknown [10.108.20.246]) by mo528.mail-out.ovh.net (Postfix) with ESMTPS id 7E05A136331A6; Fri, 28 Oct 2022 19:03:26 +0200 (CEST) Received: from localhost.localdomain (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.13; Fri, 28 Oct 2022 19:03:25 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , , Jean-Jacques Hiblot Subject: [PATCH v5 3/6] leds: provide devm_of_led_get_optional() Date: Fri, 28 Oct 2022 19:03:05 +0200 Message-ID: <20221028170308.2676734-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221028170308.2676734-1-jjhiblot@traphandler.com> References: <20221028170308.2676734-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: DAG2EX2.emp2.local (172.16.2.12) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 819092183767661019 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvgedrtdeigddutdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkphepuddvjedrtddrtddruddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhgvvgdrjhhonhgvsheslhhinhgrrhhordhorhhgpdhprghvvghlsehutgifrdgtiidprhhosghhodgutheskhgvrhhnvghlrdhorhhgpdhsvhgvnhdrshgthhifvghrmhgvrhesughishhruhhpthhivhgvqdhtvggthhhnohhlohhgihgvshdrtghomhdpkhhriiihshiithhofhdrkhhoiihlohifshhkihdoughtsehlihhnrghrohdrohhrghdpjhhohhgrnhdolhhinhgrrhhosehkvghrnhgvlhdrohhrghdpmhgrrhhijhhnrdhsuhhijhhtvghnsehsohhmrg hinhhlihhnvgdrohhrghdpsghjohhrnhdrrghnuggvrhhsshhonheslhhinhgrrhhordhorhhgpdgrnhguhidrshhhvghvtghhvghnkhhosehgmhgrihhlrdgtohhmpdhjrggtvghkrdgrnhgrshiivgifshhkihesghhmrghilhdrtghomhdplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrghdplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehvdekpdhmohguvgepshhmthhpohhuth X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 This version of devm_of_led_get() doesn't fail if a LED is not found. Instead it returns a NULL pointer. 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 2c0d979d0c8a..9cddcd908bce 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -295,6 +295,31 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, } EXPORT_SYMBOL_GPL(devm_of_led_get); +/** + * 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 ba4861ec73d3..41df18f42d00 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -215,6 +215,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.25.1