From patchwork Thu Jul 19 16:19:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 142356 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1923256ljj; Thu, 19 Jul 2018 09:19:42 -0700 (PDT) X-Received: by 2002:a1c:4489:: with SMTP id r131-v6mr4472639wma.128.1532017182796; Thu, 19 Jul 2018 09:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532017182; cv=none; d=google.com; s=arc-20160816; b=dZbHXxRqcLwWPMve/7NKsogQTUnU1yAEtCsSjupKFD52KcJsTMg4lbcg6n38jXrK2P xZ5HU2jFPQEzh8q2O/W5d2FB6pU2sdMLS4ee6fIxM/hnZdbZXcsOD1ImSzT48ST1RcFY Tvag8HZgiv3KOyQIuMIIblVsAPqVnQdih0DTsz7NDcteO6GZTffkO/kl+rXcbAXAVptu EfLwPVePzuYTYc6NmlUN7LmbOtRg8mU3v3ZXa4wrMMVX2D0HJLhXnWO1Z3Hez75YCLBs BaI158GVSaCOBLSTuRDV33ywtc6PGbr/zaXoMaGScbSXlY1Aa/KrnSLHxD8wfmxktOT5 DAVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=mtoEkUenwKXEVaYbLXYNYms73QdfgGVwiTkvGMMXbUc=; b=Aw4MBmsrb9rn/FjZKjNBpHh+CvJXdc6zE+//WWqYISdF1lQ+u8rJemXuhDy+vddAUV Pus4qFkKDJAG5o9siS/vuwXh3QqLBUak/4Qtl8t+8vidKKX3NuTrxee2uXjlUpPZdFj9 WGgPo8jL53qCZT5WzOIT+pFQFEH5GJ6U0fiCXAjwQXzeiufcxB0et92mLTvmZlDQbvTP 7wrmI3AZlVCpISrbFYOLZ11FRwc/4SCHuL1s/bW++SJx97xnAmoHP83sWyLue/1NuPC7 LkFpjOXjhyL1oovy3qgsCI9h3o9dYmR80JVqsOvSpin0X0l1IUUteA373v9ZxGHh/2lM uJaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h7HCB+Ti; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z21-v6sor1312943wma.48.2018.07.19.09.19.42 for (Google Transport Security); Thu, 19 Jul 2018 09:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h7HCB+Ti; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mtoEkUenwKXEVaYbLXYNYms73QdfgGVwiTkvGMMXbUc=; b=h7HCB+TimIpmhToaMwJaEFFBzqR+qNrE9o1oaW0duPE1abrV7PPQPZ6duGld4DAnke FSDCW+uiu/Gg0rxhhYxKBN0L1bCrk4qvROu6rRJwh82SE6tAoAj/dL/aeHfkaebJoK4U xpMckLeth5OMVrl60O0VGUoTh2YpM4CX+I8og= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mtoEkUenwKXEVaYbLXYNYms73QdfgGVwiTkvGMMXbUc=; b=t2fbbDo6RoshpOCmuzxWnkKAYYdKbxz8WAHD1Gn23LHFMHIBqm+wHZllBv/jguDF1n Azx+utShSUd7Vxa9R3z+Oi3xHW05pSoaddSfo2htn7024XCy2FFc3sDhZEyXzVKyjE0M NkWP+X5f0tJAslhl64V2kVqIvnVWzP56Q3gfgNySdEJ3iKieO3HX8CEbinFe1+I8hXjf CZJuXLKjTcIend0HOzyPvi9Zx3Q4mq1VFi/aXtdUmT6mJHvuY8yNlRJI36WB8YvIj8dT PHje6KEZ/2gNnoaycY/5EciWsjXnaW894PHM222MnRgAUTVF2Tg+puA/xenmsZAiI2WW QlQQ== X-Gm-Message-State: AOUpUlEaG0XNfgiAazRptOmtNMz/Ql4CkgZgz3TLsuQODYEvi9oPJ8Iy 23nduu5/eSDagu3Wdi056eFehWUG X-Google-Smtp-Source: AAOMgpfIqTeUDtC/mnpNFU20vWnw+LXi5Tc8gDdWQ9ZjGdUjz1URvCU7vRVr/4wiH79C2QDo++mI8Q== X-Received: by 2002:a1c:90e:: with SMTP id 14-v6mr4753800wmj.130.1532017182509; Thu, 19 Jul 2018 09:19:42 -0700 (PDT) Return-Path: 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 r125-v6sm9610361wmb.27.2018.07.19.09.19.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 09:19:41 -0700 (PDT) From: Daniel Thompson To: Lee Jones , Daniel Thompson , Jingoo Han Cc: 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: [PATCH v2] backlight: pwm_bl: Fix uninitialized variable Date: Thu, 19 Jul 2018 17:19:23 +0100 Message-Id: <20180719161923.21510-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180716210241.9457-1-daniel.thompson@linaro.org> References: <20180716210241.9457-1-daniel.thompson@linaro.org> 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(-) -- 2.17.1 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; 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) { + /* + * 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;