From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Kim, Milo" Subject: Re: [PATCH 1/2] backlight/lp855x: Refactor dt parsing code Date: Thu, 27 Nov 2014 10:32:39 +0900 Message-ID: <54767F37.3020006@ti.com> References: <1417029064-12460-1-git-send-email-seanpaul@chromium.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <1417029064-12460-1-git-send-email-seanpaul-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Sean Paul , linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: =?UTF-8?B?U3TDqXBoYW5lIE1hcmNoZXNpbg==?= , jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, cooloney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org List-Id: devicetree@vger.kernel.org (Looping backlight class subsystem maintainers) Hi Sean, Thanks for checking this. I'd like to describe why the original code is= =20 preferred. The original code is copying the values of the lp855x platform data fro= m=20 the DT in advance of allocating lp855x data. It guarantees returning quickly in case of invalid platform data. In other words, no memory allocation of lp855x proceeds if parsing the=20 DT gets failed. However, this patch allocates the lp855x first and checking the DT. Of course, devm_kzalloc() will free allocated memory later but original= =20 code does NOT try to allocate it. So I'd prefer to keep this way. Best regards, Milo On 11/27/2014 4:11 AM, Sean Paul wrote: > This patch refactors the dt parsing code to avoid setting platform_da= ta, > instead just setting lp->pdata directly. This facilitates easier > probe deferral since the current scheme would require us to clear out > dev->platform_data before deferring. > > Cc: St=C3=A9phane Marchesin > Signed-off-by: Sean Paul > --- > drivers/video/backlight/lp855x_bl.c | 37 ++++++++++++++++++--------= ----------- > 1 file changed, 18 insertions(+), 19 deletions(-) > > diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/back= light/lp855x_bl.c > index 25fb8e3..257b3ba 100644 > --- a/drivers/video/backlight/lp855x_bl.c > +++ b/drivers/video/backlight/lp855x_bl.c > @@ -341,8 +341,10 @@ static const struct attribute_group lp855x_attr_= group =3D { > }; > > #ifdef CONFIG_OF > -static int lp855x_parse_dt(struct device *dev, struct device_node *n= ode) > +static int lp855x_parse_dt(struct lp855x *lp) > { > + struct device *dev =3D lp->dev; > + struct device_node *node =3D dev->of_node; > struct lp855x_platform_data *pdata; > int rom_length; > > @@ -381,12 +383,12 @@ static int lp855x_parse_dt(struct device *dev, = struct device_node *node) > pdata->rom_data =3D &rom[0]; > } > > - dev->platform_data =3D pdata; > + lp->pdata =3D pdata; > > return 0; > } > #else > -static int lp855x_parse_dt(struct device *dev, struct device_node *n= ode) > +static int lp855x_parse_dt(struct lp855x *lp) > { > return -EINVAL; > } > @@ -395,18 +397,8 @@ static int lp855x_parse_dt(struct device *dev, s= truct device_node *node) > static int lp855x_probe(struct i2c_client *cl, const struct i2c_dev= ice_id *id) > { > struct lp855x *lp; > - struct lp855x_platform_data *pdata =3D dev_get_platdata(&cl->dev); > - struct device_node *node =3D cl->dev.of_node; > int ret; > > - if (!pdata) { > - ret =3D lp855x_parse_dt(&cl->dev, node); > - if (ret < 0) > - return ret; > - > - pdata =3D dev_get_platdata(&cl->dev); > - } > - > if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK= )) > return -EIO; > > @@ -414,16 +406,23 @@ static int lp855x_probe(struct i2c_client *cl, = const struct i2c_device_id *id) > if (!lp) > return -ENOMEM; > > - if (pdata->period_ns > 0) > - lp->mode =3D PWM_BASED; > - else > - lp->mode =3D REGISTER_BASED; > - > lp->client =3D cl; > lp->dev =3D &cl->dev; > - lp->pdata =3D pdata; > lp->chipname =3D id->name; > lp->chip_id =3D id->driver_data; > + lp->pdata =3D dev_get_platdata(&cl->dev); > + > + if (!lp->pdata) { > + ret =3D lp855x_parse_dt(lp); > + if (ret < 0) > + return ret; > + } > + > + if (lp->pdata->period_ns > 0) > + lp->mode =3D PWM_BASED; > + else > + lp->mode =3D REGISTER_BASED; > + > i2c_set_clientdata(cl, lp); > > ret =3D lp855x_configure(lp); > -- To unsubscribe from this list: send the line "unsubscribe devicetree" i= n the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html