From patchwork Sat Jun 24 08:42:14 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: 112429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6286354vqr; Sat, 24 Jun 2023 02:10:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6jr3nc4ZUiCfxs6hbt7TIEPQeFnbVWrDssoLjbGOminyQ704hqSlYwx/Knt07LR+SUBuxu X-Received: by 2002:a05:6808:2203:b0:39a:ca93:53dc with SMTP id bd3-20020a056808220300b0039aca9353dcmr32480440oib.24.1687597850306; Sat, 24 Jun 2023 02:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687597850; cv=none; d=google.com; s=arc-20160816; b=ndGqXt0zJUSHh/KobTgmoZ3RYbnlHcLE7D7N+zqDeQcs42GGKUCCx2wvsf/SM9vKOH wLFt1IU2dZC1BURCpGvnOEjC39fEBh6uAubY3HEV7xJc8+eQGRjF0YPOBwQraVbWOUrI jGRbbv+Udr16IC4NZaA/raMdZYy54KHVFgEHT8pLsquFTRpD81iYJX0e9I8B5n80abas TOUqrhiU1gbIOdxjvC5k9DV2syEkeG7pGUGRmA9BX75qWwqALs4+XaY6kyhHscEJSiP+ ImgNypRcRXR1cRnN/LBbzB+T6lfQc8SC2H5ftR6kwEV/+TwyZiHRk4Bq5THzPP/3L7Er DVMw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a170902ea0d00b001b7cbc5872dsi1010098plg.387.2023.06.24.02.10.37; Sat, 24 Jun 2023 02:10:50 -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 S231911AbjFXImp (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769574603552244064?= X-GMAIL-MSGID: =?utf-8?q?1769574603552244064?= 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