From patchwork Fri Nov 3 19:53:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 740983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E1D0C4332F for ; Fri, 3 Nov 2023 20:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjKCUz6 (ORCPT ); Fri, 3 Nov 2023 16:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234477AbjKCTxU (ORCPT ); Fri, 3 Nov 2023 15:53:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE7EDD4E; Fri, 3 Nov 2023 12:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699041198; x=1730577198; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=eUuuyUtQ+5betVlsnj9MIgKiK2+aM4+nMSQ8mwzd6Uk=; b=lZFvyC883EjBfQLF5PjSpJENPYHWPQCcvP1e5dyGvpzGxDj+WSFsdOJY Gu4nhdI+CqlYri2Vo2kZ5mX84YgPOPPbjRIdDsWCpUxBY/qSBtdROg65+ iHz/a3qALjcVOQEjEyia2yyKp+MApfUOc+zZf8IJIkK00iNW2KAS+aJKH H7M5Uu9OAK4oDJ0ky1AKxC3cihsNvmSB83Ym3TXqlimP8d7NkzsNbozcf dh3JPzpGXpY3XHviZoRs756vBYrJj4budD5wnhzVPOXrX2sNOraIBFIMJ ybIERmqSKZtbt7SEQRFck4yV34s4OqyhN9SIEByHA7GPuHFE7W740W7jK A==; X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1962960" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="1962960" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 12:53:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="761719315" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="761719315" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 03 Nov 2023 12:53:14 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B1E775E2; Fri, 3 Nov 2023 21:53:13 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Machek , Lee Jones Subject: [PATCH v1 1/4] leds: trigger: gpio: Replace custom code for gpiod_get_optional() Date: Fri, 3 Nov 2023 21:53:07 +0200 Message-Id: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org gpiod_get_optional() and currently used fwnode_gpiod_get_index() are both wrappers against the same engine internally. Since we have a pointer to struct device there is no reason to use fwnode type of GPIO call. So, replace the current fwnode call by respective gpiod ones. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/leds/trigger/ledtrig-gpio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index 9b7fe5dd5208..d91ae7fde3cf 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -89,10 +89,7 @@ static int gpio_trig_activate(struct led_classdev *led) * The generic property "trigger-sources" is followed, * and we hope that this is a GPIO. */ - gpio_data->gpiod = fwnode_gpiod_get_index(dev->fwnode, - "trigger-sources", - 0, GPIOD_IN, - "led-trigger"); + gpio_data->gpiod = gpiod_get_optional(dev, "trigger-sources", GPIOD_IN); if (IS_ERR(gpio_data->gpiod)) { ret = PTR_ERR(gpio_data->gpiod); kfree(gpio_data); @@ -104,6 +101,8 @@ static int gpio_trig_activate(struct led_classdev *led) return -EINVAL; } + gpiod_set_consumer_name(gpio_data->gpiod, "led-trigger"); + gpio_data->led = led; led_set_trigger_data(led, gpio_data); From patchwork Fri Nov 3 19:53:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 740873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE55C4332F for ; Fri, 3 Nov 2023 20:03:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345954AbjKCUDi (ORCPT ); Fri, 3 Nov 2023 16:03:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjKCUDg (ORCPT ); Fri, 3 Nov 2023 16:03:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8448DD53; Fri, 3 Nov 2023 13:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699041813; x=1730577813; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nsq+DlizAAeSWWNzWMj45TaDhpGuvaTz6ItsP0chKHM=; b=UNnN/AiPim/QbC6K9V3TJSTv/fHdm3MgCDdkEQmgxzoBoDgES3ZGEAKz qPM3qgJxCR3OYErmgVuvZQNnzwZQuvtdp69stzuyMOJ2Ni2BfQcbhBiIW rq3Vs7zDixiHxZDTdSo4bwajL8jHl7SjcANnEKWXRRhtn1IzIG+XJjNw3 AndQPAbH1G143BI7KvZuDHHul7h9FnNkHGbvcPYhYHAGBwqWuigIJbOlM HulBxIzA6YKUiEqVaZ1GsBllI5ZXYch+gJ0X/gVCOw5kuc0abQyl7heHp 4SKM1jjb+7o/pCt2eN2wsINNi9rOoBTDS92Df4wx4pYPLfarmZHlVx688 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1894389" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="1894389" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 13:03:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="832126756" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="832126756" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 03 Nov 2023 13:03:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C26B82A6; Fri, 3 Nov 2023 21:53:13 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Machek , Lee Jones Subject: [PATCH v1 2/4] leds: trigger: gpio: Convert to use kstrtox() Date: Fri, 3 Nov 2023 21:53:08 +0200 Message-Id: <20231103195310.948327-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> References: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org sscanf() is a heavy one and moreover requires additional boundary checks. Convert driver to use kstrtou8() in gpio_trig_inverted_store(). Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/leds/trigger/ledtrig-gpio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index d91ae7fde3cf..8a30f9228186 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -53,14 +53,12 @@ static ssize_t gpio_trig_brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev); - unsigned desired_brightness; + u8 desired_brightness; int ret; - ret = sscanf(buf, "%u", &desired_brightness); - if (ret < 1 || desired_brightness > 255) { - dev_err(dev, "invalid value\n"); - return -EINVAL; - } + ret = kstrtou8(buf, 10, &desired_brightness); + if (ret) + return ret; gpio_data->desired_brightness = desired_brightness; From patchwork Fri Nov 3 19:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 740872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 018EDC4167D for ; Fri, 3 Nov 2023 20:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbjKCUz7 (ORCPT ); Fri, 3 Nov 2023 16:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378183AbjKCTxT (ORCPT ); Fri, 3 Nov 2023 15:53:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D0551BC; Fri, 3 Nov 2023 12:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699041197; x=1730577197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M2LYr3uiwRiw2hfh8eZTwB7i1h0z6rfdmlPTebmD3d0=; b=j7XwkUNJ9/9TsLf520/+Oq7tI0HVVk7sYI7K0eruNZwAHHTp5APL7stF ZVXqMFPr5J9hxpl56MZqOTuz7X8rVz02qvb7q+JwGhbazGD8vjv9j0Tgm BZkbTz6vSK1Q5goHNQWEjetBUCNSR147I8aNDCVlDiOsFgUYGSOZhDPTD M3CO2M/HdpYagw0KrFQxAF+UPwueJuYHdDSWEzmEqTPyTYYbQ8GrO38Iq bBPMNXOwGsfLszNJ195wjaFfGZqCewALS3ov//dt99aBXUDXqW2AJdZqT cXizvIKbCfllAC9U5mKGTWNUVwu1Bc1FhAAwkGk8g0rCK6aW+JzUdtaEp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1962964" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="1962964" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 12:53:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="761719316" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="761719316" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 03 Nov 2023 12:53:14 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D66EC5E8; Fri, 3 Nov 2023 21:53:13 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Machek , Lee Jones Subject: [PATCH v1 3/4] leds: trigger: gpio: Use sysfs_emit() to instead of s*printf() Date: Fri, 3 Nov 2023 21:53:09 +0200 Message-Id: <20231103195310.948327-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> References: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/leds/trigger/ledtrig-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index 8a30f9228186..8824be19881f 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -46,7 +46,7 @@ static ssize_t gpio_trig_brightness_show(struct device *dev, { struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev); - return sprintf(buf, "%u\n", gpio_data->desired_brightness); + return sysfs_emit(buf, "%u\n", gpio_data->desired_brightness); } static ssize_t gpio_trig_brightness_store(struct device *dev, From patchwork Fri Nov 3 19:53:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 740984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA049C4167D for ; Fri, 3 Nov 2023 20:03:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229553AbjKCUDe (ORCPT ); Fri, 3 Nov 2023 16:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjKCUDd (ORCPT ); Fri, 3 Nov 2023 16:03:33 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB1AD53; Fri, 3 Nov 2023 13:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699041809; x=1730577809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IHEKAZwFkfBPaWXKiUvpj74KxQIC1qIeU1pZ07Sbhuk=; b=ka5Ntg+C7w4STO2qIpzuQFROo4DFF88qtg3GH56S9UtrlFwmoQPoxKLQ pzMD6vgeXBG7cbFntiBgtu2tOxS08LdLaEYXcu+G4NI0wUZdFmUdpCI44 MfkgsoqTGXCGEnyUVEVdUbzRj3chiMb3Gi4O/MaSIcuXIpCj2a65gMOH9 5s5NKgCxtkjnKzWdDGszJFlk+KHMhm85ftX0B6it+/hoIKYuuiDG4dq9s YRr0pcAMa6/F3+FRDassWoPl2S8jbK/MJ4XbrdD84DABk5dBTVfjz9G4z iRV6qlAkQg5X8tKfo4hUZWvuhNaiVUJggtHhtJi/fHXzJyAqmixmvFwWW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="420130012" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="420130012" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 13:03:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="905446864" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="905446864" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 03 Nov 2023 13:03:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E5BE05E5; Fri, 3 Nov 2023 21:53:13 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Machek , Lee Jones Subject: [PATCH v1 4/4] leds: trigger: gpio: Convert to DEVICE_ATTR_RW() Date: Fri, 3 Nov 2023 21:53:10 +0200 Message-Id: <20231103195310.948327-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> References: <20231103195310.948327-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Instead of custom wrapper, use DEVICE_ATTR_RW() directly. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/leds/trigger/ledtrig-gpio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index 8824be19881f..7f6a2352b0ac 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -41,7 +41,7 @@ static irqreturn_t gpio_trig_irq(int irq, void *_led) return IRQ_HANDLED; } -static ssize_t gpio_trig_brightness_show(struct device *dev, +static ssize_t desired_brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev); @@ -49,7 +49,7 @@ static ssize_t gpio_trig_brightness_show(struct device *dev, return sysfs_emit(buf, "%u\n", gpio_data->desired_brightness); } -static ssize_t gpio_trig_brightness_store(struct device *dev, +static ssize_t desired_brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev); @@ -64,8 +64,7 @@ static ssize_t gpio_trig_brightness_store(struct device *dev, return n; } -static DEVICE_ATTR(desired_brightness, 0644, gpio_trig_brightness_show, - gpio_trig_brightness_store); +static DEVICE_ATTR_RW(desired_brightness); static struct attribute *gpio_trig_attrs[] = { &dev_attr_desired_brightness.attr,