Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp714785ybn; Wed, 2 Oct 2019 05:09:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWT/q3eafR65uai5tL0WrzzGvrRBR0n8KQCTHjai3UEMaImY0FSJcclL0KOS5x48buTQrW X-Received: by 2002:a17:906:3495:: with SMTP id g21mr2771610ejb.100.1570018198936; Wed, 02 Oct 2019 05:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570018198; cv=none; d=google.com; s=arc-20160816; b=P/kHmAi3SYzpoe1XEJ3BQMlPc5gb6XTE/emBHczhS+Bh/wvp/oCBuL5AhZk8GeHOxK vhkvTEHikdzHpuzpKIMMAFsXUUrji8sNVBid6kKVMMfY/QYezd+nlf4N5ImHgwkT4dvG f4mVIGmmp7tDTs1X8+KIzOG+kW5YZPAyK+2evR4/USuThH9q4cCnVK6zyvlAtdAV9+Gg 8DdJ1Kjr1/bKgBQI1+Y+0dRrLZOAm6DUzoRDq2YwV/tKNzv6nOYHohIi8SM2JWsto+D3 9f1n+yx+yeNlEcRB8u2Dmy55cMP1Wq+QEXiNyq+qCGWpFljC33KOaqQox/yAwJUFCpBb OEtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wUZHS/G+/EfCLIw5f+SykywrhoRFuqH9n5f7oduoqzw=; b=keUAbcH/zrsplRmUCFNIiRhqP/+5yd9tm4YJruDeNNWj9DIl0Eakp5om98Z4JZ6rkS 4Dz/qxg/1F6pxp8CXYAZ8SX5ieExzZ7ZlkTLPXJuOB0Z2dv8M/ojfOzbGCd6NxMwNxX0 ApT1/oR76l/DvIw6xwNuhsFqejKtsMbGZ2yKfPpvDB2CNU8QilX+n5vXX72pbve33fMe IMXo6j4UNOfkzEnQeh+C7htD9RPOHm4Bto4vWfqyT+LL+ofsgfHJMOTLPVPLMI3RbQ+v uRQD6q1tKihnU9lvVxKaoZhNqRjWIM3UJfBT1PHsSfdBW0z5xKnoYYAcrYfgiojugWq4 Jojw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aPJlKuY+; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si10312528eju.3.2019.10.02.05.09.34; Wed, 02 Oct 2019 05:09:58 -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=@linaro.org header.s=google header.b=aPJlKuY+; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbfJBKdX (ORCPT + 99 others); Wed, 2 Oct 2019 06:33:23 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35179 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbfJBKdX (ORCPT ); Wed, 2 Oct 2019 06:33:23 -0400 Received: by mail-wm1-f66.google.com with SMTP id y21so6418612wmi.0 for ; Wed, 02 Oct 2019 03:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wUZHS/G+/EfCLIw5f+SykywrhoRFuqH9n5f7oduoqzw=; b=aPJlKuY+eRR4q5p4jV4qCpE0b1aKVkj4+PZrZUlv5v56zXOetpNPtg02as20aFegDv 7TeZz7ikn+LWA9jblA9+VZiAVm1XySTwn2milAAYnC2Rzv7xJY//GDYipTlAoQ3KMQ4R CwpYuupqRmGdKbHBvIqoOJDP6OlRiysRgy9YYBruBRJvud2PD7QBdtZ7f2ujAweX5ku2 ssysEGjpCUtCqvPzBNgRpqRR3fDgveWyhWxUpQ3dreoWvdrLvl7FOJeJIR3Wx/Q+SQnc IB1CtCW//A0NqLofsKyy8Il33UA302qkDIijV1Rcz7nCZXrsqmtcBOv+PpAGlO4pRa2N zHuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wUZHS/G+/EfCLIw5f+SykywrhoRFuqH9n5f7oduoqzw=; b=BziXVbwHSTDdgqRlP0d/sXTeT8F4Jf3YaxTHmnL5him0YcywfPRiL7hEJazp9bwGZs six+s5BC+ACg5KaY4Y585HwoWbqaDwO3XBws3z0fc1EVkk3q3ldQdnEdTx60mB+8eNYz A2Rfwb0CME2v8anF4EpbmkwKDe4UpHWVmWbfMI0rmaYWYLB2ija60uIty/vsKtUWvkR5 l1YZZhOVVOr1oj4gxLHr888qO/TAUH/XPFDzmKRsPhttXviFfeAT7WnmxkpNAi3VbWh8 JYr5YeXjRkYSdtFWfvX4uf8024qNaOmWXU+FnqDCl7uVDnIa4P2dKEgbfs6dySzXAGls NLAg== X-Gm-Message-State: APjAAAWAuGlUHH546YTkqO9dvsaH8irGbGDYWZMJKP3wE6RUxT4J2FhZ X93AtqNyhXUoBkNTFBHynDdP2Q== X-Received: by 2002:a1c:2bc7:: with SMTP id r190mr2439604wmr.143.1570012400648; Wed, 02 Oct 2019 03:33:20 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id l10sm26838984wrh.20.2019.10.02.03.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2019 03:33:20 -0700 (PDT) Date: Wed, 2 Oct 2019 11:33:18 +0100 From: Daniel Thompson To: Bartosz Golaszewski Cc: Yoshinori Sato , Rich Felker , Lee Jones , Jingoo Han , Bartlomiej Zolnierkiewicz , Linus Walleij , Andy Shevchenko , Jacopo Mondi , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v4 7/7] backlight: gpio: pull gpio_backlight_initial_power_state() into probe Message-ID: <20191002103318.6owxberhml6mbtxm@holly.lan> References: <20191001125837.4472-1-brgl@bgdev.pl> <20191001125837.4472-8-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191001125837.4472-8-brgl@bgdev.pl> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 01, 2019 at 02:58:37PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > The probe function in the gpio-backlight driver is quite short. If we > pull gpio_backlight_initial_power_state() into probe we can drop two > more fields from struct gpio_backlight and shrink the driver code. > > Signed-off-by: Bartosz Golaszewski > --- > drivers/video/backlight/gpio_backlight.c | 36 ++++++++---------------- > 1 file changed, 12 insertions(+), 24 deletions(-) > > diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c > index 6247687b6330..37ec184f0c5c 100644 > --- a/drivers/video/backlight/gpio_backlight.c > +++ b/drivers/video/backlight/gpio_backlight.c > @@ -17,11 +17,8 @@ > #include > > struct gpio_backlight { > - struct device *dev; > struct device *fbdev; > - > struct gpio_desc *gpiod; > - int def_value; > }; > > static int gpio_backlight_update_status(struct backlight_device *bl) > @@ -53,41 +50,24 @@ static const struct backlight_ops gpio_backlight_ops = { > .check_fb = gpio_backlight_check_fb, > }; > > -static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl) I'm inclined to view deleting this function as removing a comment (e.g. the function name helps us to read the code)! Removing the variables from the context structure is good but why not just pass them to the function and let the compiler decided whether or not to inline. Daniel. > -{ > - struct device_node *node = gbl->dev->of_node; > - > - /* Not booted with device tree or no phandle link to the node */ > - if (!node || !node->phandle) > - return gbl->def_value ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; > - > - /* if the enable GPIO is disabled, do not enable the backlight */ > - if (gpiod_get_value_cansleep(gbl->gpiod) == 0) > - return FB_BLANK_POWERDOWN; > - > - return FB_BLANK_UNBLANK; > -} > - > - > static int gpio_backlight_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev); > + struct device_node *of_node = dev->of_node; > struct backlight_properties props; > struct backlight_device *bl; > struct gpio_backlight *gbl; > - int ret; > + int ret, def_value; > > gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL); > if (gbl == NULL) > return -ENOMEM; > > - gbl->dev = dev; > - > if (pdata) > gbl->fbdev = pdata->fbdev; > > - gbl->def_value = device_property_read_bool(dev, "default-on"); > + def_value = device_property_read_bool(dev, "default-on"); > > gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS); > if (IS_ERR(gbl->gpiod)) { > @@ -109,7 +89,15 @@ static int gpio_backlight_probe(struct platform_device *pdev) > return PTR_ERR(bl); > } > > - bl->props.power = gpio_backlight_initial_power_state(gbl); > + /* Not booted with device tree or no phandle link to the node */ > + if (!of_node || !of_node->phandle) > + bl->props.power = def_value ? FB_BLANK_UNBLANK > + : FB_BLANK_POWERDOWN; > + else if (gpiod_get_value_cansleep(gbl->gpiod) == 0) > + bl->props.power = FB_BLANK_POWERDOWN; > + else > + bl->props.power = FB_BLANK_UNBLANK; > + > bl->props.brightness = 1; > > backlight_update_status(bl); > -- > 2.23.0 >