Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp77087ybn; Thu, 3 Oct 2019 01:43:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz/a3FalK4ul8ly+DyjClncYf5UL9O2F5T3Xb7d3J37r54gDOLfgUd1HjJAgYPC7RGHNjp X-Received: by 2002:a17:907:41db:: with SMTP id og19mr6725001ejb.307.1570092229984; Thu, 03 Oct 2019 01:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570092229; cv=none; d=google.com; s=arc-20160816; b=LwOOQikscyqDFO2Mj30cv45lB23QxVXBPU5hfK3Y+GfohmxcAYkSwWBc+yCKRb12no /iTp41zXY1wz4hgwq57Gk6bSv5CkqFxW1WdcpT8yZ4iYq4rM/UxjjecEEOoWLCJIiO/3 9kva7wO/Vj6ODPUSGZdwXtydcaE6Gze+TGeoYIpcE05VRjh+S5G9QdY+zqI/HCvm5fHK zM18oXQiEQCBqNKJa++Yh9ksi7tKePnYz1fX384tJwQC2bkYldmTO77VAetNrG4eZZIB F21uTfeUkMOxr2ZC0FSxWOelePaZgYCWwFLgn8nlSDFDpJCwZjeVdQ1Mbpsr4NAYuz/2 FSDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TiAsOmTXWY5+HeIiqR4tev653INweUDzmx4DD0U/7BE=; b=h317wcn5/X/65jRd5IIBDa9rfW+hFv0Z2s52qoKJa5PjjZvxwfwl8tV8kXnSKWaSp3 jOXU2i+1FLpc+2w/9mpBZlcMuWhd+Q1hOmNWmgvYcxVlFTYD3fjdpkBrmP/0YCY240qh uJGoDwr7Z8ndbukRAk9/4smPVMh6pet4mn4r9b4zWoP9Q7i0JItHFnrI4ksWzJVnepx5 dBdf5qedLd4ZmAkRd+LOVUXBhyjSB0TGKBDtUp551cvr6S0D+y56jUsecHqO8F7JpiOl 3BPyEWyvJauH01gEpEQ+MCjEmsH5FJy3S9+lEUpJwvfJZuwxULbS8HEg0AoHQYrHdyHj d5Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=vMHgQ0VT; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g38si1053230edg.127.2019.10.03.01.43.19; Thu, 03 Oct 2019 01:43:49 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=vMHgQ0VT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729024AbfJCImf (ORCPT + 99 others); Thu, 3 Oct 2019 04:42:35 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:38317 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729004AbfJCImd (ORCPT ); Thu, 3 Oct 2019 04:42:33 -0400 Received: by mail-io1-f67.google.com with SMTP id u8so3645225iom.5 for ; Thu, 03 Oct 2019 01:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TiAsOmTXWY5+HeIiqR4tev653INweUDzmx4DD0U/7BE=; b=vMHgQ0VTHyTFrHAZHjAmsBhYqgtl/goTUm3lB8eodLZIJ40pK5CXD8fc/SVM1zZJTd fkCjyEq372rTfvmxR+bhgfDmK+hLh+Q0iTMUT8qmHtQLS1hwt/3cWm7d39o7BNdLCnGO 0Zlcour6vhFnVmmkDTXpy/9lDQSbVW1ljr0kKHXmwB/QGFDNPt6E5wjbyVx6oenehDmB PQa0G7jPYmuaFwpGiRsDAkVCQF6MNuSaEs8lHZjEZMUeRdhVeqEIm1sY4KWMSh+llXDX zVMEq9dqE+659LatNkQIJvzTdKDsNleeA91k3sOixtTsljSBdTawUMSRGCxv1yR1W6sO uv3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TiAsOmTXWY5+HeIiqR4tev653INweUDzmx4DD0U/7BE=; b=aKbAc8aT2NKppENqMN2x10MNWVqdkJ6bucHVB+6epXUJ19OSHXPL8R2rjiV8hkzx2L xam9okWg0q5ZunuKy7bg3okEAa6Ma0zWFspu33BkEKtaUewImZL7esgh/CmAM6RjGlWx EzREOl1rJo5CLl7vFPyXn3jNfHhpqjYlStGNM+Ac4sqSjJr4gQ/Uk6VoL+1QwrZWD3Iv KVWIFkKJUrtUNAqB9hq8e5hTh0vd5XDmWgicbIwXBZTCFAIfPV7Z22VatmzjtrKbSZ5b myc6YRxOvd+cpByNKMN8jRdRMO2gYMb3L7PUVxs3tuHGjEp1KjucE7sgHuzdml8g8sL/ BKVQ== X-Gm-Message-State: APjAAAVzaSSBFAqlISeJDnu0MSyAJyfIhvakMfjEkuvBCIKI2py95IAY c2frsA2vngmeOWpTerxP80o9JXoc5Zr4P3BicUcZ7g== X-Received: by 2002:a6b:fc04:: with SMTP id r4mr6861002ioh.189.1570092152368; Thu, 03 Oct 2019 01:42:32 -0700 (PDT) MIME-Version: 1.0 References: <20191001125837.4472-1-brgl@bgdev.pl> <20191001125837.4472-8-brgl@bgdev.pl> <20191002103318.6owxberhml6mbtxm@holly.lan> <20191002144028.6lljre76zxd52oui@holly.lan> In-Reply-To: <20191002144028.6lljre76zxd52oui@holly.lan> From: Bartosz Golaszewski Date: Thu, 3 Oct 2019 10:42:21 +0200 Message-ID: Subject: Re: [PATCH v4 7/7] backlight: gpio: pull gpio_backlight_initial_power_state() into probe To: Daniel Thompson Cc: Yoshinori Sato , Rich Felker , Lee Jones , Jingoo Han , Bartlomiej Zolnierkiewicz , Linus Walleij , Andy Shevchenko , Jacopo Mondi , linux-sh@vger.kernel.org, Linux Kernel Mailing List , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =C5=9Br., 2 pa=C5=BA 2019 o 16:40 Daniel Thompson napisa=C5=82(a): > > On Wed, Oct 02, 2019 at 01:46:17PM +0200, Bartosz Golaszewski wrote: > > =C5=9Br., 2 pa=C5=BA 2019 o 12:33 Daniel Thompson napisa=C5=82(a): > > > > > > 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 tw= o > > > > 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/vid= eo/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 *b= l) > > > > @@ -53,41 +50,24 @@ static const struct backlight_ops gpio_backligh= t_ops =3D { > > > > .check_fb =3D gpio_backlight_check_fb, > > > > }; > > > > > > > > -static int gpio_backlight_initial_power_state(struct gpio_backligh= t *gbl) > > > > > > I'm inclined to view deleting this function as removing a comment (e.= g. > > > the function name helps us to read the code)! > > > > > > > Right, but why not just add a comment then? > > I guess you could add a comment but keeping it pulled out in a function > makes it easier to compare against equivalent code in other drivers > (such as pwm_bl). > The pwm driver seems to be the only one that has this function and it's also much more complicated. Unless it's a hard NACK, I think that pulling all initialization into probe looks better and shrinks the driver visually. Bart > > Daniel. > > > > The probe function is 50 > > lines long, there's really no need to split it. This will get inlined > > anyway too. > > > > Bart > > > > > Removing the variables from the context structure is good but why not > > > just pass them to the function and let the compiler decided whether o= r > > > not to inline. > > > > > > > > > Daniel. > > > > > > > > > > -{ > > > > - struct device_node *node =3D 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_P= OWERDOWN; > > > > - > > > > - /* if the enable GPIO is disabled, do not enable the backligh= t */ > > > > - if (gpiod_get_value_cansleep(gbl->gpiod) =3D=3D 0) > > > > - return FB_BLANK_POWERDOWN; > > > > - > > > > - return FB_BLANK_UNBLANK; > > > > -} > > > > - > > > > - > > > > static int gpio_backlight_probe(struct platform_device *pdev) > > > > { > > > > struct device *dev =3D &pdev->dev; > > > > struct gpio_backlight_platform_data *pdata =3D dev_get_platda= ta(dev); > > > > + struct device_node *of_node =3D dev->of_node; > > > > struct backlight_properties props; > > > > struct backlight_device *bl; > > > > struct gpio_backlight *gbl; > > > > - int ret; > > > > + int ret, def_value; > > > > > > > > gbl =3D devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL); > > > > if (gbl =3D=3D NULL) > > > > return -ENOMEM; > > > > > > > > - gbl->dev =3D dev; > > > > - > > > > if (pdata) > > > > gbl->fbdev =3D pdata->fbdev; > > > > > > > > - gbl->def_value =3D device_property_read_bool(dev, "default-on= "); > > > > + def_value =3D device_property_read_bool(dev, "default-on"); > > > > > > > > gbl->gpiod =3D 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 =3D 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 =3D def_value ? FB_BLANK_UNBLANK > > > > + : FB_BLANK_POWERDOWN; > > > > + else if (gpiod_get_value_cansleep(gbl->gpiod) =3D=3D 0) > > > > + bl->props.power =3D FB_BLANK_POWERDOWN; > > > > + else > > > > + bl->props.power =3D FB_BLANK_UNBLANK; > > > > + > > > > bl->props.brightness =3D 1; > > > > > > > > backlight_update_status(bl); > > > > -- > > > > 2.23.0 > > > >