Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2128030imm; Mon, 16 Jul 2018 02:43:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdijgZku6sOYxXKK1CIvJfluaFKeHk1HmMzHl3ZZjWIM7DdNs9ySkGQqHTp0uE5Qd6TA6pH X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr15699871pli.191.1531734204125; Mon, 16 Jul 2018 02:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531734204; cv=none; d=google.com; s=arc-20160816; b=K/GDB1EWDMYbM9LTmj/a+pRLkz1iGX//gdJzgOQQcAl0uI/AmMy8NcTnOlqiB0Y55L uw0SaSWgW9J/HyOw4WK29dOk3zLYqRl2j8YFivYlyjHVwh22iPoSIG+nAhfoWTd9RL5s OUrH9F7bSmZ38EdN4hW3XMldWp/+8rblP1GkDJbnOrmW03TK6xN0E+YQuMmXmdf+VQhi PWzGKa9wsz2y0Jse0gWmO8NhcdoJNA8SKPyI90dng5TFYck8JguMCB2N+8GYncBbouVq TUvi8DWPY7vwRX29n9covcjJZQVeUCYQdIoH+xfEjYJGfDdfdCiDtzxKI/6e5fjxClsg NtCA== 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:arc-authentication-results; bh=oS3xqMIpl+z4S4ul6WDSiiVEVRZ/IkVRh0cwp9iOrFg=; b=EsWKCf22PoMYV6z3+w1RjBzg0oKbIDGfTLaB+OtbTuZP1jKCxmNdV+tzzOfV4Qr3E2 AdrqebRmJtzNPogUYV9diV4OyHQu0XVdKxzQ67BCbl+sPIePBlZI6S546IZLxB9LI/vG tTMZJ+a9iTO7nBz2yHtxDO202KjfSz8gsLzfxalWCqdvDUp+ognc/JdoaQ9sqeVylq1B JZkJdXY8KSEoZcbRIJxOQp1USdFHi5+zSW+GNGSaQXmeoprUmrbf5+Z1NYf4TtUzfhBS HkGy8ob6L0NSiwwZMLwMfBah2whewlj1oG4XdNXLNwp85Em0n6Lrp4UdDISjdpnKl7vf rVog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P5ERh8YB; 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 n184-v6si28373213pga.98.2018.07.16.02.43.09; Mon, 16 Jul 2018 02:43:24 -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=P5ERh8YB; 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 S1728734AbeGPKJC (ORCPT + 99 others); Mon, 16 Jul 2018 06:09:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43796 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728160AbeGPKJC (ORCPT ); Mon, 16 Jul 2018 06:09:02 -0400 Received: by mail-wr1-f66.google.com with SMTP id b15-v6so31208910wrv.10 for ; Mon, 16 Jul 2018 02:42:27 -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=oS3xqMIpl+z4S4ul6WDSiiVEVRZ/IkVRh0cwp9iOrFg=; b=P5ERh8YBmFKIRFAVfJDgRb0eFQW/JV/Iy9OiiDmQyB2HmXBFYa7wIKjbltV0FDuumj XVQGEGuTlyA5EizCQC5wfC4kEh+f1yyychw3dRdZoQF9KT0qWtY4QYgvyQK7WMQjUBf9 SFErZIIzG5/J1eE6RNoX2FcqR2nGab7ZzR7Zg= 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=oS3xqMIpl+z4S4ul6WDSiiVEVRZ/IkVRh0cwp9iOrFg=; b=tQsbhdqa/6VGcHwGYhMVoN84/4TCWRh0DYsGCqGvQ1epyUWoGJVG569t/gpFJO43++ 5hCQbh/g22NzEhEpmjMYJDqUfroliMkXaGtxPWRJYtpRUgL4suW4dZpSfRgoapCjMqPQ 8jJrekn8GKFaPxRMgdcLD2muxAcqLa3KudQKWSITAyGpbwIBRF25JfL3bwJTcPwCqXb+ i/zjMCjTdpPveuxOtarNSxXzJ8ZV8zLgV6YW6wj2NeLkox7FzJESpd6yJHmU5/qmyrEK pmjWstlqNOgMDjI2nGtxovWgy0/1hIJOR6lQW+6iHXaytDV+mIWq9ONBklP978DKNcCF 7L3A== X-Gm-Message-State: AOUpUlHPttRBg2f6pGp5hOP+e7b7cy4vpe9AbDi/6JU7z4YvCzu9gmZ4 wBoxMET1hcLmDWN7zbR3j08zXw== X-Received: by 2002:adf:91e5:: with SMTP id 92-v6mr11019801wri.124.1531734147256; Mon, 16 Jul 2018 02:42:27 -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 63-v6sm22647496wmo.22.2018.07.16.02.42.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 02:42:26 -0700 (PDT) Date: Mon, 16 Jul 2018 10:42:23 +0100 From: Daniel Thompson To: Marcel Ziswiler Cc: "rpurdie@rpsys.net" , "linux-kernel@vger.kernel.org" , "dianders@google.com" , "robh+dt@kernel.org" , "jingoohan1@gmail.com" , "enric.balletbo@collabora.com" , "linux-leds@vger.kernel.org" , "jacek.anaszewski@gmail.com" , "devicetree@vger.kernel.org" , "kernel@collabora.com" , "briannorris@google.com" , "pavel@ucw.cz" , "lee.jones@linaro.org" , "amstan@google.com" , "groeck@google.com" Subject: Re: REGRESSION: [RESEND PATCH v3 1/4] backlight: pwm_bl: linear interpolation between brightness-levels Message-ID: <20180716094223.syzwviia4wdx74yh@holly.lan> References: <20180409083333.1249-1-enric.balletbo@collabora.com> <20180409083333.1249-2-enric.balletbo@collabora.com> <1531580895.7579.7.camel@toradex.com> <20180715075732.GA2989@wychelm.lan> <1531664796.7579.13.camel@toradex.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1531664796.7579.13.camel@toradex.com> User-Agent: NeoMutt/20180622 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 15, 2018 at 02:26:44PM +0000, Marcel Ziswiler wrote: > On Sun, 2018-07-15 at 08:57 +0100, Daniel Thompson wrote: > > On Sat, Jul 14, 2018 at 03:08:17PM +0000, Marcel Ziswiler wrote: > > > On Mon, 2018-04-09 at 10:33 +0200, Enric Balletbo i Serra wrote: > > > > diff --git a/drivers/video/backlight/pwm_bl.c > > > > b/drivers/video/backlight/pwm_bl.c > > > > index 8e3f1245f5c5..f0a108ab570a 100644 > > > > --- a/drivers/video/backlight/pwm_bl.c > > > > +++ b/drivers/video/backlight/pwm_bl.c > > > > @@ -147,7 +147,11 @@ static int pwm_backlight_parse_dt(struct > > > > device > > > > *dev, > > > > struct > > > > platform_pwm_backlight_data > > > > *data) > > > > { > > > > struct device_node *node = dev->of_node; > > > > + unsigned int num_levels = 0; > > > > + unsigned int levels_count; > > > > + unsigned int num_steps; > > > > num_steps is not initialized... > > > > > > > > struct property *prop; > > > > + unsigned int *table; > > > > int length; > > > > u32 value; > > > > int ret; > > > > @@ -167,6 +171,7 @@ static int pwm_backlight_parse_dt(struct > > > > device > > > > *dev, > > > > /* read brightness levels from DT property */ > > > > if (data->max_brightness > 0) { > > > > size_t size = sizeof(*data->levels) * data- > > > > > max_brightness; > > > > > > > > + unsigned int i, j, n = 0; > > > > > > > > data->levels = devm_kzalloc(dev, size, > > > > GFP_KERNEL); > > > > if (!data->levels) > > > > @@ -184,6 +189,84 @@ static int pwm_backlight_parse_dt(struct > > > > device > > > > *dev, > > > > return ret; > > > > > > > > data->dft_brightness = value; > > > > + > > > > + /* > > > > + * This property is optional, if is set enables > > > > linear > > > > + * interpolation between each of the values of > > > > brightness levels > > > > + * and creates a new pre-computed table. > > > > + */ > > > > + of_property_read_u32(node, "num-interpolated- > > > > steps", > > > > + &num_steps); > > > > ... this is not guaranteed to initialized num_steps ... > > Yes, as it only does so if returning zero. I do further propose to > check its return value as well. Isn't that what return values are used > for? I don't much mind either way. I originally wrote the patch you shared below but then decided to ask you to test and, since I didn't compile test before doing so, I opted for something more immune to silly mistakes. > Quoting from include/linux/of.h: > > Search for a property in a device node and read 32-bit value(s) from > it. Returns 0 on success, -EINVAL if the property does not exist, > -ENODATA if property does not have a value, and -EOVERFLOW if the > property data isn't large enough. > > > > > + > > > > + /* > > > > + * Make sure that there is at least two entries > > > > in > > > > the > > > > + * brightness-levels table, otherwise we can't > > > > interpolate > > > > + * between two points. > > > > + */ > > > > + if (num_steps) { > > > > ... and we make a decision on it here. > > > > Marcel: Can you try the following quick fix? It's untested on my side > > but very simple... > > > > From 6fa2fbeb017086147ac61981107a95cb8ae7b4e7 Mon Sep 17 00:00:00 > > 2001 > > From: Daniel Thompson > > Date: Sun, 15 Jul 2018 08:49:05 +0100 > > Subject: [PATCH] backlight: pwm_bl: Fix uninitialized variable > > > > Currently, if the DT does not define num-interpolated-steps then > > num_steps is undefined meaning the interpolation code will deploy > > randomly. Fix this. > > > > Fixes: 573fe6d1c25c ("backlight: pwm_bl: Linear interpolation between > > brightness-levels") > > Reported-by: Marcel Ziswiler > > Signed-off-by: Daniel Thompson > > --- > > drivers/video/backlight/pwm_bl.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/video/backlight/pwm_bl.c > > b/drivers/video/backlight/pwm_bl.c > > index 9ee4c1b735b2..bdfcc0a71db1 100644 > > --- a/drivers/video/backlight/pwm_bl.c > > +++ b/drivers/video/backlight/pwm_bl.c > > @@ -250,7 +250,7 @@ static int pwm_backlight_parse_dt(struct device > > *dev, > > struct device_node *node = dev->of_node; > > unsigned int num_levels = 0; > > unsigned int levels_count; > > - unsigned int num_steps; > > + unsigned int num_steps = 0; > > struct property *prop; > > unsigned int *table; > > int length; > > -- > > 2.17.1 > > From dbb31d00c9f2873affedbceae917c9d7fce5f832 Mon Sep 17 00:00:00 2001 > Message-Id: rcel.ziswiler@toradex.com> > From: Daniel Thompson > Date: Sun, 15 Jul 2018 08:49:05 +0100 > Subject: [PATCH] backlight: pwm_bl: Fix uninitialized variable > > Currently, if the DT does not define num-interpolated-steps then > num_steps is undefined meaning the interpolation code will deploy > randomly. Fix this. > > Fixes: 573fe6d1c25c ("backlight: pwm_bl: Linear interpolation between > brightness-levels") > Reported-by: Marcel Ziswiler > Signed-off-by: Daniel Thompson > Signed-off-by: Marcel Ziswiler Is it Tested-by: too? It would be good to confirm I was right about the cause of the problem. > --- > drivers/video/backlight/pwm_bl.c | 18 ++++++++---------- > 1 file changed, 8 insertions(+), 10 deletions(-) > > diff --git a/drivers/video/backlight/pwm_bl.c > b/drivers/video/backlight/pwm_bl.c > index 9ee4c1b735b2..e884d589378d 100644 > --- a/drivers/video/backlight/pwm_bl.c > +++ b/drivers/video/backlight/pwm_bl.c > @@ -250,7 +250,7 @@ static int pwm_backlight_parse_dt(struct device > *dev, > struct device_node *node = dev->of_node; > unsigned int num_levels = 0; > unsigned int levels_count; > - unsigned int num_steps; > + unsigned int num_steps = 0; This can go. If we check the return code them this variable is no longer used uninitialized [I'm OK to make the change though... since you've kept my name at the top ;-) ]. Daniel. > struct property *prop; > unsigned int *table; > int length; > @@ -299,15 +299,13 @@ static int pwm_backlight_parse_dt(struct device > *dev, > * interpolation between each of the values of > brightness levels > * and creates a new pre-computed table. > */ > - of_property_read_u32(node, "num-interpolated-steps", > - &num_steps); > - > - /* > - * Make sure that there is at least two entries in the > - * brightness-levels table, otherwise we can't > interpolate > - * between two points. > - */ > - if (num_steps) { > + if ((of_property_read_u32(node, "num-interpolated- > steps", > + &num_steps) == 0) && > (num_steps)) { > + /* > + * Make sure that there is at least two > entries in the > + * brightness-levels table, otherwise we can't > interpolate > + * between two points. > + */ > if (data->max_brightness < 2) { > dev_err(dev, "can't interpolate\n"); > return -EINVAL; > -- > 2.14.4