Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6637637imm; Mon, 23 Jul 2018 23:50:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfu/kNgr7KNwBiFoBx1YU1szf8gvbebR3l30x2ShW/hiMs7VhVcvX4Qnyu2h4paRojbvdUK X-Received: by 2002:a63:5463:: with SMTP id e35-v6mr15328006pgm.115.1532415032706; Mon, 23 Jul 2018 23:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415032; cv=none; d=google.com; s=arc-20160816; b=PHwUV10AsR3mFZtc/mhz3fRbOItXQMVzZZxeTwuVWEQB3wEQSiwQWfdQpn/35q0oIS f4ru97xsCtaj7E9xINMPuTDxKwYmLialRv0xLPDcvdSRJYdYPFlMABEdz8AxRbn9LMRN Ih2C6dmI90X0r+4JBm4k4ofGiOQG4SQuoiP53w3L41pTx4gyuRZZkwJ6WVX7lDx9l12k 4rNHfs8jYh76duJuA/3gm5Igdcwov5pHwD7qGBUmXeuys5z2w3IZC16OpcGMuYURzbxo GYJXe0DfZEOnQ5otX7D5Ev7cYJQYO4Kp87aJYUAF4CQ8fqbXNcs42UkFqTVb7h9OW8Ha 8eZQ== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=9XvvxHx62kPldJUgplHkNa/jr5/VhOm1NzcJ0R1f/Z4=; b=PnW0eatSNffNN+0e1juNDGaJg5tthRB5gKLdeUn+svqsePu/bjw44ScDqPyPlHSyJ6 U6hsxjZaJEsPnyWDSJohqM+4CfqYW5rXk3bSTTVw7GU3ClE0P6cU0sjJ58/mzyNrHEFw uwtXj92hOngHCGdhCs4zttsc2t4oalcbSGHNZZz60Wmb1Thp50sqC8eTgn3ePg2tzwG0 fX6mtVbpuIF+GBZXta3m5QGIT+H6PU5TBvl3yCfh1Gvu8FQe6TJbCz5P2e4LRid+Nov5 y0NX30FI3Is6WLU43WYvh3MIoX75ozVZ6ph6ZtmLE/vx1t44UsW30EgSe+Two4kyM8A5 Y6DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iMJ+atwg; 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 u12-v6si10386089pgb.280.2018.07.23.23.50.17; Mon, 23 Jul 2018 23:50:32 -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=iMJ+atwg; 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 S2388389AbeGXHxp (ORCPT + 99 others); Tue, 24 Jul 2018 03:53:45 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38303 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388351AbeGXHxp (ORCPT ); Tue, 24 Jul 2018 03:53:45 -0400 Received: by mail-wr1-f66.google.com with SMTP id v14-v6so2931987wro.5 for ; Mon, 23 Jul 2018 23:48:48 -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:content-transfer-encoding:in-reply-to :user-agent; bh=9XvvxHx62kPldJUgplHkNa/jr5/VhOm1NzcJ0R1f/Z4=; b=iMJ+atwgCVlBCNdOjqnPBhKPimuAhnMsHHuJLGqvsdX+5pvI7RaFDgyiPF4Anf3fgx X+qCfYiona8F3Odyz+Hj3zetlCmZmYOwR+VNg3G+8bqAcISYi31CwSSA/Fny74LSVX+k 5pUlTYWtFel7+8iawR6UTPtYPyiJx2HLATr8M= 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:content-transfer-encoding :in-reply-to:user-agent; bh=9XvvxHx62kPldJUgplHkNa/jr5/VhOm1NzcJ0R1f/Z4=; b=EdenKfIGmc1tGsvVIDlAnLkpeb/JOxl8v91F8NEGjFyR3+C9F7MxmekHmLq/qtHgbX 5Y1/Pc+2PnSRtw4SYLEZ1Y3LmbVuD486O5QpRxVVGijoDB7UUzD7+VI+HOuUrsAfKJk8 tn0gw9GiNFuHE3KfPtTkSp83PU7QR6KkVE6LahT+g5fZ5POUPqgPybotwhnlOjlzfwS7 ED9Z0FhgDP7YxSbLe8iIFN2//DvmW7UW9sL6sAqdEeDyCyrivJFJ+6RoZCLmwPJkk+al Wknb542/8m191UXDiMOuMAU9ChAqPmEGUdx8j/NcbFCOTJ7Vef3xf93liOQvAICnxQzq A3Cg== X-Gm-Message-State: AOUpUlFy2lvOdCTlgJyfIAlsKlFISzEsof+gnrQSglSva/ratg+CnLcT oLexUb9LcKb2zoRA/n42IfhlPQ== X-Received: by 2002:adf:9c12:: with SMTP id f18-v6mr10724705wrc.93.1532414927912; Mon, 23 Jul 2018 23:48:47 -0700 (PDT) Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id z5-v6sm12901303wrv.2.2018.07.23.23.48.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 23:48:46 -0700 (PDT) Date: Tue, 24 Jul 2018 07:48:43 +0100 From: Daniel Thompson To: Lee Jones Cc: Jingoo Han , Thierry Reding , Bartlomiej Zolnierkiewicz , Marcel Ziswiler , linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: Re: [PATCH v2] backlight: pwm_bl: Fix uninitialized variable Message-ID: <20180724064843.GA3099@wychelm.lan> References: <20180716210241.9457-1-daniel.thompson@linaro.org> <20180719161923.21510-1-daniel.thompson@linaro.org> <20180723072343.GD4213@dell> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180723072343.GD4213@dell> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 23, 2018 at 08:23:43AM +0100, Lee Jones wrote: > On Thu, 19 Jul 2018, Daniel Thompson wrote: > > > Currently, if the DT does not define num-interpolated-steps then > > num_steps is undefined and the interpolation code will deploy randomly. > > Fix this. > > > > Additionally fix a small grammar error that was identified and > > tighten up return code checking of DT properties, both of which came > > up during review of this patch. > > > > Fixes: 573fe6d1c25c ("backlight: pwm_bl: Linear interpolation between > > brightness-levels") > > Reported-by: Marcel Ziswiler > > Signed-off-by: Daniel Thompson > > Tested-by: Marcel Ziswiler > > --- > > > > Notes: > > v2: > > - Simplify SoB chain (with Marcel's permission) > > - Separate complex if statement and make other similar calls use same > > return code checking approach > > - Tidy up comment formatting and fix pre-existing grammar error > > > > drivers/video/backlight/pwm_bl.c | 25 ++++++++++++------------- > > 1 file changed, 12 insertions(+), 13 deletions(-) > > I'm hesitant to provide feedback on this, as I feel as though I've > messed you around enough, however ... ;) > > > diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c > > index 9ee4c1b735b2..f7799f62fea0 100644 > > --- a/drivers/video/backlight/pwm_bl.c > > +++ b/drivers/video/backlight/pwm_bl.c > > @@ -284,30 +284,29 @@ static int pwm_backlight_parse_dt(struct device *dev, > > ret = of_property_read_u32_array(node, "brightness-levels", > > data->levels, > > data->max_brightness); > > - if (ret < 0) > > + if (!ret) > > return ret; > > > > ret = of_property_read_u32(node, "default-brightness-level", > > &value); > > - if (ret < 0) > > + if (!ret) > > return ret; > > Just FYI (it didn't even make it to 'nit' status), this should really > be done in a separate patch since it is unrelated to the rest of the > patch. > > > 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. > > + * 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) { > > + ret = of_property_read_u32(node, "num-interpolated-steps", > > + &num_steps); > > + if (!ret || num_steps) { > > Not sure if it's even possible for of_property_read_u32() to fail AND > still populate num_steps, however this check makes it sound like that's > okay. Is that correct? No, it's bogus. Looks like when I broke the if statement into two clauses I ended up flipping the && to an ||. > I can't help but think that this all 'just goes away' if you > pre-initialise num_steps. I wouldn't let the "do not initialise too > far away from the code using variable" affect this. However, if > you're insistent, perhaps consider moving the declaration to just > below: > > if (data->max_brightness > 0) { > > > + /* > > + * Make sure that there are 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; > > -- > Lee Jones [李琼斯] > Linaro Services Technical Lead > Linaro.org │ Open source software for ARM SoCs > Follow Linaro: Facebook | Twitter | Blog