Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1162847yba; Thu, 16 May 2019 15:42:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyu/ow+DDrmeTelHVj9MbNxAGCDnb6gj5FNDqG7rYR2RzGZwNu8WMR8I9jShh/L5P4oFwZ4 X-Received: by 2002:a63:8242:: with SMTP id w63mr52545165pgd.169.1558046534935; Thu, 16 May 2019 15:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558046534; cv=none; d=google.com; s=arc-20160816; b=JgzIpVftrU/2MXbP+ezznk4QTK0m331tRXZmRl+VlOCRyc9WSJOhRnna+xoq46vHuE Bwpn01PyegyT/BqjN8DP9hWffIBbUpclpNcqSvgee5ym6YbM2FFy2g9+HUpiZ4Hr6PYo Gwg2F3iNb1/tdxV9Sv7vd+j0i4/31hu2ilye7vuTeJCWj1cBwDLWMFEVIOJxpA66O+qU VPYjB/RQLZqatuaubJInNlqs8bgCQJUvRfdNurgQHsPrvUpg4U88gwsvEaL4fiIJw8mZ 8odWmXk197XeYAidcI34R3KTnXbRTh6pbqjGtj6/lSu//gLkSAFRtntB1UkaVEhrlxaP XT9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=9bgH5ddVtCLjQIU2Q7/Cyhth48wZAFNpISOX0pGwTj8=; b=d5Vqh3pS7fZj5ZuKhhAxALS7uAzycEmVqAtWlBxarUXgZ7uxe230sw0XjOhbHeUgrH owKQN1tGeHCM8+KGq4vWef7jPyGYrbbNKnxpSWb9LkTFmpWgaKlmgLBuBvIW6UnvTB8w j2AjeidvKZhaqNFGj1aSsECEjhmxmm0z9gc39RPhyAw7tG3c09WzIUffuFAwDc56qjOE 1vNPSP7y0l78s2I9KeVpLrhfhLPHmE3L9ricPt2ANP7ek4LETTnhiEHT8GkuY0ydhgi5 n90J3LayzVHTXdu9SntmizinN8G5JVAy2BBzLFFUxHx9pxHqSwxcXWwRtehl796OR9pF WHUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uIB9HLyq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si6557434pgs.135.2019.05.16.15.41.59; Thu, 16 May 2019 15:42:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uIB9HLyq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728825AbfEPVmh (ORCPT + 99 others); Thu, 16 May 2019 17:42:37 -0400 Received: from mail-ot1-f74.google.com ([209.85.210.74]:47250 "EHLO mail-ot1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728813AbfEPVmf (ORCPT ); Thu, 16 May 2019 17:42:35 -0400 Received: by mail-ot1-f74.google.com with SMTP id e88so2320228ote.14 for ; Thu, 16 May 2019 14:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=9bgH5ddVtCLjQIU2Q7/Cyhth48wZAFNpISOX0pGwTj8=; b=uIB9HLyqlIkDQpDDHN7iA1Zy9AFgPFTWgf8H4VfTEOnVMBmcsUvgBm23XCDsmQ6FVi T+Qa/wMIn0MAMTaaFvSu/9INMeroOP5Q3HATux072BRRqoEqgjtzGUQbk0T/HkjsVYxt UHOFmW8T+dEsN0TggqHI5R6I5JDRz6J685ecazye0TpS2RSX9pvhZ71MWiLGbzUIuvqQ eGXQ6x2R4VT+a+xKuO93JiskvjnJnojPkiCuKgnoyQ5gHpqsPm7Ce9E9xiGO2fhPcU0m k5MLgAZya5yi9GSGmavy0RvHuIu5zO5we1CczznoKIulzYH08hOEZd9dZ9GmiaKdrB4Y eVlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9bgH5ddVtCLjQIU2Q7/Cyhth48wZAFNpISOX0pGwTj8=; b=AuLNfMLzfh+Wdb9q6iFhDDN+SchBzyW3bxHYRc0lqxftZ7q38VUHWZtJSGsqfC1fQI 6zIN5AEdqUXlmw0vlzLAM4bx4lX95PwV0qM5IqCEMr/vsjoahn6ybQUMiNSSA62Mbrwd Edzxvzs2DtJ1i0P7A7v+enHjOonwT48igI0+O41l4vg84zxe/g3pVI8Sa9S6nLUL7sI6 vv9NAkDs/CMb9Oe7lY8ZHk7knSNE27gtAlnHnET1USA+goefdQ+JMl1ELCnMuNjrPOwR FUWeUdrYz/qYhegtgLBAfO15JSBhlLllr4ZNRzQ4rrSxSBnsany8ZiQMrRIqx6LxsmaZ 0EEA== X-Gm-Message-State: APjAAAUwlgq0TBAoNXswWd5bDWFceRGZHjG4U+jUbr1eNXpZ9kTo8bQp vEnlSwF84AieUxwytcmXJpGnLjYkOQ== X-Received: by 2002:aca:f007:: with SMTP id o7mr11981585oih.59.1558042955083; Thu, 16 May 2019 14:42:35 -0700 (PDT) Date: Thu, 16 May 2019 14:42:09 -0700 In-Reply-To: <20190516214209.139726-1-kunyi@google.com> Message-Id: <20190516214209.139726-3-kunyi@google.com> Mime-Version: 1.0 References: <20190516214209.139726-1-kunyi@google.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH 2/2] ledtrig-gpio: 0 is a valid GPIO number From: Kun Yi To: linux-leds@vger.kernel.org Cc: Kun Yi , jacek.anaszewski@gmail.com, pavel@ucw.cz, dmurphy@ti.com, u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GPIO number 0 is a valid case to handle. Use -1 as initial value and use gpio_is_valid() to determine validity of the GPIO number. Signed-off-by: Kun Yi Change-Id: I4a29f98b237fd0d8ba4dd2a28219d4429f2ccfff --- drivers/leds/trigger/ledtrig-gpio.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index f6d50e031492..48d8ef8538bd 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -22,7 +22,7 @@ struct gpio_trig_data { unsigned desired_brightness; /* desired brightness when led is on */ unsigned inverted; /* true when gpio is inverted */ - unsigned gpio; /* gpio that triggers the leds */ + int gpio; /* gpio that triggers the leds */ }; static irqreturn_t gpio_trig_irq(int irq, void *_led) @@ -114,13 +114,12 @@ static ssize_t gpio_trig_gpio_show(struct device *dev, { struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev); - return sprintf(buf, "%u\n", gpio_data->gpio); + return sprintf(buf, "%d\n", gpio_data->gpio); } -static inline void free_used_gpio_if_valid(unsigned int gpio, - struct led_classdev *led) +static inline void free_used_gpio_if_valid(int gpio, struct led_classdev *led) { - if (gpio == 0) + if (!gpio_is_valid(gpio)) return; free_irq(gpio_to_irq(gpio), led); @@ -144,12 +143,6 @@ static ssize_t gpio_trig_gpio_store(struct device *dev, if (gpio_data->gpio == gpio) return n; - if (!gpio) { - free_used_gpio_if_valid(gpio_data->gpio, led); - gpio_data->gpio = 0; - return n; - } - ret = gpio_request(gpio, "ledtrig-gpio"); if (ret) { dev_err(dev, "gpio_request failed with error %d\n", ret); @@ -195,6 +188,7 @@ static int gpio_trig_activate(struct led_classdev *led) return -ENOMEM; gpio_data->led = led; + gpio_data->gpio = -1; led_set_trigger_data(led, gpio_data); return 0; -- 2.21.0.1020.gf2820cf01a-goog