Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13544398rwd; Sat, 24 Jun 2023 02:09:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4faENp3WwyYJ5mBjlM7r8/H8/But7i9oEPiGa9dfxbvWoK+B8PRqNN/83Hx3NtEpSnvarz X-Received: by 2002:a05:6808:bd4:b0:3a0:3161:ee2f with SMTP id o20-20020a0568080bd400b003a03161ee2fmr17258678oik.57.1687597780044; Sat, 24 Jun 2023 02:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687597779; cv=none; d=google.com; s=arc-20160816; b=qKZ+vG44qTzn9qTBwxb13qxwZKZVMldOpsbtvbd7oRKORq0fMpqBxpWUXQg9zWuO/w P/bK9k/ooVaeuD5rEVkipmV3iZt9nr8cBtFcVo/0L2p/eNvJHQZEK81kGHBycC9WTKMc QCEQWtD5O3hENJZWxZHdMbG7lkqUvs//biwULQe9AXigUp1L57hWo4pS8SyoYKxRfNNa 3x6puQPD+lPVvfGsHqexfU9DlCpg6Ouo0PwR+aaouU3VB+AWa94kP6rCcveMOFPlfKxF pWdpeSR9cb6qhJr9c5qS+Gj79pYrI9KNWvTQHS9MZy9Yu87i6uhPuoLgkk2XoFDhBJmp Govg== 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=zXd8zKw3zYhJaKrPqJZydrWWFB6X+Pv4tOTAma0ECTo=; fh=Nth8QeOoSsYrDungiTCJAFNyO964yBoXQVDGwhneIeA=; b=ikNbbA+AcCCF3v9IChPTHcPCIGTvbbFcvUHEngz41y8qS1YqL6TfZrWmIqm6YNEtrC 08kjwOoaWFJphorOV5k9HDdHzxfK+s9FhTZ5I19voxq4IwiL4LyoJTY01yV1iNwnAMYs TW1zw3hc9yyk43zDdf8h+fhl+sxqpBgMs4X0lHFHwxtHaILetbssbCqmKV+emcGollTZ DJB/mw0XSdrgGrqwTJlVNmQvGw22mm3liwAwXfr3b9ru9wYxc0ullU5Gln7/pmRxSCvA vgcohPCfF/udD/VKTNeUv33gyhgNkUvcHfz/+UeC2G0/L/rtuz7sp9mDm0a/69Q+c2z0 hWvQ== 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 e10-20020a17090301ca00b001ae4d1c1288si1061781plh.279.2023.06.24.02.09.26; Sat, 24 Jun 2023 02:09:39 -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 S232760AbjFXImp (ORCPT + 99 others); Sat, 24 Jun 2023 04:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbjFXImj (ORCPT ); Sat, 24 Jun 2023 04:42:39 -0400 Received: from 5.mo563.mail-out.ovh.net (5.mo563.mail-out.ovh.net [46.105.53.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7931BE45; Sat, 24 Jun 2023 01:42:36 -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 873FB22F20; Sat, 24 Jun 2023 08:42:34 +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 ; Sat, 24 Jun 2023 08:42:34 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.108.20.150]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id 29E8D2011E0; Sat, 24 Jun 2023 08:42:34 +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; Sat, 24 Jun 2023 10:42:33 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot , Andy Shevchenko Subject: [PATCH v10 2/5] leds: provide devm_of_led_get_optional() Date: Sat, 24 Jun 2023 10:42:14 +0200 Message-ID: <20230624084217.3079205-3-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230624084217.3079205-1-jjhiblot@traphandler.com> References: <20230624084217.3079205-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: DAG2EX1.emp2.local (172.16.2.11) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 12428246125770455431 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrgeegjedgtdejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppedtrddtrddtrddtpdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopeguihhrvggtthhorhdurdguvghrphdrmhgrihhlqdhouhhtrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeife 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=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 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