linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Weiss <luca@z3ntu.xyz>
To: linux-leds@vger.kernel.org, Dan Murphy <dmurphy@ti.com>
Cc: Heiko Stuebner <heiko@sntech.de>, Icenowy Zheng <icenowy@aosc.io>,
	Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Maxime Ripard <mripard@kernel.org>, Pavel Machek <pavel@ucw.cz>,
	Rob Herring <robh+dt@kernel.org>, Shawn Guo <shawnguo@kernel.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH v2 2/2] leds: add sgm3140 driver
Date: Sat, 04 Apr 2020 11:36:39 +0200	[thread overview]
Message-ID: <5847770.lOV4Wx5bFT@g550jk> (raw)
In-Reply-To: <e29c3fee-068d-c3d7-a0e6-6877a616b3fa@ti.com>

Hi Dan,

On Freitag, 3. April 2020 19:31:52 CEST Dan Murphy wrote:
> Luca
> 
> On 3/30/20 2:47 PM, Luca Weiss wrote:
> > Add a driver for the SGMICRO SGM3140 Buck/Boost Charge Pump LED driver.
> > 
> > This device is controlled by two GPIO pins, one for enabling and the
> > second one for switching between torch and flash mode.
> > 
> > Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
> > ---
> > Changes since v1:
> > - Add vin-supply (keep track of 'enabled' state for that)
> > - Wrap lines
> > - static const -ify some structs and methods
> > - use strscpy instead of strlcpy
> > - remove u32 cast by adding 'U' suffix to constants
> > - rebase on linux-next
> > 
> >   drivers/leds/Kconfig        |   9 +
> >   drivers/leds/Makefile       |   1 +
> >   drivers/leds/leds-sgm3140.c | 317 ++++++++++++++++++++++++++++++++++++
> >   3 files changed, 327 insertions(+)
> >   create mode 100644 drivers/leds/leds-sgm3140.c
> > 
-snip-
> > +
> > +	priv->vin_regulator = devm_regulator_get(&pdev->dev, "vin");
> > +	ret = PTR_ERR_OR_ZERO(priv->vin_regulator);
> > +	if (ret) {
> > +		if (ret != -EPROBE_DEFER)
> > +			dev_err(&pdev->dev,
> > +				"Failed to request regulator: 
%d\n", ret);
> > +		return ret;
> 
> This regulator is optional so why would you return here?  You should
> only return if -EPROBE_DEFER.

If the regulator is not specified in the dts, then a dummy regulator will be 
used:

[    1.027114] sgm3140 sgm3140: sgm3140 supply vin not found, using dummy 
regulator

So this code will only be called if something really failed (or was defered)

> 
> > +	}
> > +
> > +	child_node = of_get_next_available_child(pdev->dev.of_node, NULL);
> 
> Maybe this should be the first check before doing all the processing to
> make sure that the DT is not
> 
> malformed.

If e.g. the devm_gpiod_get calls fail (because the gpios weren't declared in 
the dts) then the dt is also "malformed" which isn't as different as the 
subnode being missing imo. I don't think it matters much here. And this way I 
don't have to care about calling of_node_put in case of an error for the 
statements above.

> 
> > +	if (!child_node) {
> > +		dev_err(&pdev->dev,
> > +			"No DT child node found for connected LED.
\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	ret = of_property_read_u32(child_node, "flash-max-timeout-us",
> > +				   &priv->max_timeout);
> > +	if (ret) {
> > +		priv->max_timeout = FLASH_MAX_TIMEOUT_DEFAULT;
> > +		dev_warn(&pdev->dev,
> > +			 "flash-max-timeout-us DT property 
missing\n");
> > +	}
> > +
> > +	/*
> > +	 * Set default timeout to FLASH_DEFAULT_TIMEOUT except if 
max_timeout
> > +	 * from DT is lower.
> > +	 */
> > +	priv->timeout = min(priv->max_timeout, FLASH_TIMEOUT_DEFAULT);
> > +
> > +	timer_setup(&priv->powerdown_timer, sgm3140_powerdown_timer, 0);
> > +
> > +	fled_cdev = &priv->fled_cdev;
> > +	led_cdev = &fled_cdev->led_cdev;
> > +
> > +	fled_cdev->ops = &sgm3140_flash_ops;
> > +
> > +	led_cdev->brightness_set_blocking = sgm3140_brightness_set;
> > +	led_cdev->max_brightness = LED_ON;
> > +	led_cdev->flags |= LED_DEV_CAP_FLASH;
> > +
> > +	sgm3140_init_flash_timeout(priv);
> > +
> > +	init_data.fwnode = of_fwnode_handle(child_node);
> > +
> > +	platform_set_drvdata(pdev, priv);
> > +
> > +	/* Register in the LED subsystem */
> > +	ret = devm_led_classdev_flash_register_ext(&pdev->dev,
> > +						   
fled_cdev, &init_data);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "Failed to register flash device: 
%d\n",
> > +			ret);
> > +		goto err;
> > +	}
> > +
> > +	sgm3140_init_v4l2_flash_config(priv, &v4l2_sd_cfg);
> > +
> > +	/* Create V4L2 Flash subdev */
> > +	priv->v4l2_flash = v4l2_flash_init(&pdev->dev,
> > +					   
of_fwnode_handle(child_node),
> > +					   fled_cdev, NULL,
> > +					   &v4l2_sd_cfg);
> > +	if (IS_ERR(priv->v4l2_flash)) {
> > +		ret = PTR_ERR(priv->v4l2_flash);
> > +		goto err;
> 
> Not sure why this is here you are not in a for loop and this will fall
> through anyway to the err label.
> 

I kept the goto in, in case more code is added below that statement so the 
author doesn't forget that this error needs to be handled.
If wanted I can remove it of course.

> > +	}
> > +
> > +err:
> > +	of_node_put(child_node);
> > +	return ret;
> > +}
> > +
> 
> Dan

Regards
Luca



  reply	other threads:[~2020-04-04  9:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 19:47 [PATCH v2 0/2] Add sgm3140 flash led driver Luca Weiss
2020-03-30 19:47 ` [PATCH v2 1/2] dt-bindings: leds: Add binding for sgm3140 Luca Weiss
2020-04-03 17:21   ` Dan Murphy
2020-04-10 17:41   ` Rob Herring
2020-03-30 19:47 ` [PATCH v2 2/2] leds: add sgm3140 driver Luca Weiss
2020-04-03 17:31   ` Dan Murphy
2020-04-04  9:36     ` Luca Weiss [this message]
2020-04-04 13:56       ` Dan Murphy
2020-04-04  9:58   ` Andy Shevchenko
2020-04-05 18:45     ` Luca Weiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5847770.lOV4Wx5bFT@g550jk \
    --to=luca@z3ntu.xyz \
    --cc=devicetree@vger.kernel.org \
    --cc=dmurphy@ti.com \
    --cc=heiko@sntech.de \
    --cc=icenowy@aosc.io \
    --cc=jacek.anaszewski@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mripard@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).