Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1285429rwb; Thu, 15 Dec 2022 08:22:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf77y+QYyZjstH9nUsKufSeCNzg89GfOavcoBUil8P7JNKxjJvbBrCk+BU0ZK4cJ05XPGdYJ X-Received: by 2002:a17:902:9b93:b0:189:8c38:cb96 with SMTP id y19-20020a1709029b9300b001898c38cb96mr27749225plp.20.1671121333291; Thu, 15 Dec 2022 08:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671121333; cv=none; d=google.com; s=arc-20160816; b=TUBhVhAi/g4G67VnWflWJrBq8sXqDGceowWA4tlweld013M+4wLW/FFb+Vzm+QBOaP 8LlJicMI9v8LO1dtd2GgJ9+yiM7ICt22DMYbVmbyB5Q4z2QoFWZhoReEGOAo3WM29dMp 6pXcfAazH0FnfyBLk5EDpxIA2tNkrwGt1q6i8H0MUo2ZTl65NUvew8flhpTCh7rZ2ipf 9moqgI53BXZlZEKSdk0boAoPJWTtv1qsUPT3tPuPYkYALYpM+wDqQJzY8qiwLXyvXoky YbczcRJZ9TYVSK7ujWIm5xWOQphmMlxsDv/ErTZJiO/xRELOEcQzbM4FI6prYrLrkuf1 fqoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pQq23aBLz2m2Qb/o0dxmFq0n0pj+yPa65DscBOK8wdk=; b=pKex23D+0258ixPxE9MSXyHmkbVKRMJg3j/vHKzqGZZqW+OMTmxdFvDJs6oT/ntnsI ZiRapSD6OfalVd5fHXGwJsMpOY7ONIdV0CWluF3X3zesVxUCMIGGwbsrZlz8NwEyAmxe juphMm+/B1huS4MYerxJ4IoeMo/4TmtShZfYE9inB3WqlSxm2FHqhphp0klHZ795Q+Md laCTHIj9sdtCQIDksADaYqkjR+Ah5av490oTQGSFAc1LhAlFQwmGhX6LgsRWK11Judw9 IdTxVu6z2qfnlLOTb5Uxr0mf8svNnk0vRQIiRelyjZ0BnoQ8zhKMKQJTF42v+AgSOM7y eogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=ph8Zhq1S; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a170902d2cf00b001899477302bsi6851750plc.588.2022.12.15.08.22.04; Thu, 15 Dec 2022 08:22:13 -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; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=ph8Zhq1S; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbiLOQNd (ORCPT + 69 others); Thu, 15 Dec 2022 11:13:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbiLOQNX (ORCPT ); Thu, 15 Dec 2022 11:13:23 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ADC131EE4; Thu, 15 Dec 2022 08:13:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=pQq23aBLz2m2Qb/o0dxmFq0n0pj+yPa65DscBOK8wdk=; b=ph8Zhq1SIqIA9pbenDsYgg/e2H KleIJOozdYhH1f/ZplayPuwLMlUiLf6z3/WUgtW1YO4UFanERFzVrGKkU+Zt92bejno3Zpiju+npB a1SGBHcNnhkR/EhXe//Rjf7sqJ15yWhH6EjN/Xypu400PHhv/5iu25gJRjjV+A5dtn+KV+TjFvTYW BFAOVOacBZYSC30bU8TQ7ZLbKjb54dQfOOFu7R7aU2ku8lrlBz9yKXD7hw8JKXXSC73SuPPrLk70O FnmSpWcKYKxFLxVUwF4PFSxjj4dFIcp1jl5QhCxD9sYBS7q7DmehdqtFVE7uYbChwsHivjAvj43Zq Q1oQVTfQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35720) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1p5qr6-0003Hw-BH; Thu, 15 Dec 2022 16:13:08 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1p5qr1-0008U9-BS; Thu, 15 Dec 2022 16:13:03 +0000 Date: Thu, 15 Dec 2022 16:13:03 +0000 From: "Russell King (Oracle)" To: Christian Marangi Cc: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Pavel Machek , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-leds@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Marek =?iso-8859-1?Q?Beh=FAn?= Subject: Re: [PATCH v7 01/11] leds: add support for hardware driven LEDs Message-ID: References: <20221214235438.30271-1-ansuelsmth@gmail.com> <20221214235438.30271-2-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221214235438.30271-2-ansuelsmth@gmail.com> Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Hi Christian, Thanks for the patch. I think Andrew's email is offline at the moment. On Thu, Dec 15, 2022 at 12:54:28AM +0100, Christian Marangi wrote: > +static bool led_trigger_is_supported(struct led_classdev *led_cdev, > + struct led_trigger *trigger) > +{ > + switch (led_cdev->blink_mode) { > + case SOFTWARE_CONTROLLED: > + if (trigger->supported_blink_modes == HARDWARE_ONLY) > + return 0; > + break; > + case HARDWARE_CONTROLLED: > + if (trigger->supported_blink_modes == SOFTWARE_ONLY) > + return 0; > + break; > + case SOFTWARE_HARDWARE_CONTROLLED: > + break; > + default: > + return 0; > + } > + > + return 1; Should be returning true/false. I'm not sure I'm a fan of the style of this though - wouldn't the following be easier to read? switch (led_cdev->blink_mode) { case SOFTWARE_CONTROLLED: return trigger->supported_blink_modes != HARDWARE_ONLY; case HARDWARE_CONTROLLED: return trigger->supported_blink_modes != SOFTWARE_ONLY; case SOFTWARE_HARDWARE_CONTROLLED: return true; } ? Also, does it really need a default case - without it, when the led_blink_modes enum is expanded and the switch statement isn't updated, we'll get a compiler warning which will prompt this to be updated - whereas, with a default case, it won't. > @@ -188,6 +213,10 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) > led_set_brightness(led_cdev, LED_OFF); > } > if (trig) { > + /* Make sure the trigger support the LED blink mode */ > + if (!led_trigger_is_supported(led_cdev, trig)) > + return -EINVAL; Shouldn't validation happen before we start taking any actions? In other words, before we remove the previous trigger? > @@ -350,12 +381,26 @@ static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev) > > #define TRIG_NAME_MAX 50 > > +enum led_trigger_blink_supported_modes { > + SOFTWARE_ONLY = SOFTWARE_CONTROLLED, > + HARDWARE_ONLY = HARDWARE_CONTROLLED, > + SOFTWARE_HARDWARE = SOFTWARE_HARDWARE_CONTROLLED, I suspect all these generic names are asking for eventual namespace clashes. Maybe prefix them with LED_ ? Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!