Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2990285rwl; Tue, 27 Dec 2022 02:44:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXs3Lxq2kNG+cpAtxtHdOP8Ls0tsZBwueh49+Q0mL3sdCjtBGSDJ8NHQJ99paXCrmdwXnSKf X-Received: by 2002:a17:90a:de92:b0:219:396c:9e30 with SMTP id n18-20020a17090ade9200b00219396c9e30mr24514481pjv.20.1672137855310; Tue, 27 Dec 2022 02:44:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672137855; cv=none; d=google.com; s=arc-20160816; b=V+rVF9YE2spO3Gnd7166aMhTFdG5ZYypZf6/ue/XobylCq9dy/NZiBQ1tMC/JVgm53 gzBA2vabjqBYS5/N0soayl0e4Ob8UXYrGk6wbYIFvYrz8bGxTxNZwcOgt8afNBvaiw2Y Mi7YVerSYTNub60wbdifBOrRZU27DawuT3HXGmBkxHAC3R3dd/U2CbMFMtwWIqVMMYAu av6CbEv6qLeEuM1ThWvPQzwkN/ZmwZv599YqbZPdDi/kv0aNFLv6cUOW1KXZzJv14x17 PVPxNsMTnpTh62NDUJw70lANZ3Mlk+GtGiGFUeuCnPDg8kZlTyxPQQrl2Ha6+Fq4VrMI iS2g== 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=ELc0mhiNYkXDq6vU5dsvDudfOTzbMXb1KLoKmhTvQ3hFUu3ofixsZILlmUfidmJcUN 9dNMGWy5YXDBLrruoMIaWrxncR4B6RG9OVi2KeVxTq2PGl9kdGIXdUio3p9BaQndEaaT 9nFmT04zSAjiAMswcQuG7XaRDSe7lePW7W3v1eeXaQcOGgLCIhrI9Dls0xY8AZhDN3P0 focdDglZmmsAv6+68jINY9BHGVw8GO6Wk89BEL/wj5O7XpxbW0TCg0Hau0B088nIV7/E 9jRhXp+2ikAQ/yOOlHxn5jz+xDmqiWhQveDnrT5EC4tKKio23rX1L8P8N9iZwa50JNIA iyNQ== 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 il8-20020a17090b164800b00212def0cbedsi19708184pjb.8.2022.12.27.02.44.06; Tue, 27 Dec 2022 02:44:15 -0800 (PST) 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 S231620AbiL0KYV (ORCPT + 66 others); Tue, 27 Dec 2022 05:24:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231335AbiL0KYG (ORCPT ); Tue, 27 Dec 2022 05:24:06 -0500 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 8B6199FE9; Tue, 27 Dec 2022 02:24:05 -0800 (PST) Received: from pro2.mail.ovh.net (unknown [10.108.1.71]) by mo528.mail-out.ovh.net (Postfix) with ESMTPS id 0A341147C1BF4; Tue, 27 Dec 2022 11:07:07 +0100 (CET) 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.16; Tue, 27 Dec 2022 11:07:06 +0100 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , , Jean-Jacques Hiblot Subject: [RESEND PATCH v6 3/6] leds: provide devm_of_led_get_optional() Date: Tue, 27 Dec 2022 11:06:56 +0100 Message-ID: <20221227100659.157071-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221227100659.157071-1-jjhiblot@traphandler.com> References: <20221227100659.157071-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: DAG3EX1.emp2.local (172.16.2.21) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 14108370259400866267 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedriedtgdduudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppeduvdejrddtrddtrddupdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqedpnhgspghrtghpthhtohepuddprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrghdpphgrvhgvlhesuhgtfidrtgiipdhrohgshhdoughtsehkvghrnhgvlhdrohhrghdpshhvvghnrdhstghhfigvrhhmvghrseguihhsrhhuphhtihhvvgdqthgvtghhnhholhhoghhivghsrdgtohhmpdhkrhiihihsiihtohhfrdhkohiilhhofihskhhiodgutheslhhinhgrrhhordhorhhgpdhjohhhrghnodhlihhnrghroheskhgvrhhnvghlrdhorhhgpdhmrghrihhjnhdrshhuihhjthgvnhesshhomhgrihhnlhhinhgvrd horhhgpdgsjhhorhhnrdgrnhguvghrshhsohhnsehlihhnrghrohdrohhrghdprghnugihrdhshhgvvhgthhgvnhhkohesghhmrghilhdrtghomhdpjhgrtggvkhdrrghnrghsiigvfihskhhisehgmhgrihhlrdgtohhmpdhlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpuggvvhhitggvthhrvggvsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhohedvkedpmhhouggvpehsmhhtphhouhht X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL,SPF_HELO_NONE,SPF_NONE 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 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