Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp725973imm; Wed, 18 Jul 2018 09:35:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcWga/GcSxe4NSi7CFXz0YU255W53bMjmz7JguObc81jwtaxnKGowGYr0hsFoMME9w2sSox X-Received: by 2002:a63:b605:: with SMTP id j5-v6mr6541714pgf.437.1531931743383; Wed, 18 Jul 2018 09:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531931743; cv=none; d=google.com; s=arc-20160816; b=JqDYiB9kZ3I0nNuwrXkg/xVxMc8E5R4cwhFDmnJRdgiBqujSwXk34a7ozMD9vPPqdy l2oh5Fbit0bYJL8KFbbsebt3w3OZ0qi2AnWgCknlDJVhxm5dkvXBpZ5FtTIrTrYmQfXn HUKPoc4gbOr/tuUnj+Z8hjs91MPSxYUt7NvYKtF0JzVCToY6Z5fDwNqfw69zBPEiIX0A gnOEJkz2q7QEgBez26tXjNNzI0hE8SHErMdcFiV7auH1YtMqnVlxi9ztJncmRR3FPXh7 Quna44DKRz84NKYlINYG+dc0HYtJGm9CtsRgu7JHcPZRw1Ico/k9CZmd3COxhyUV88Ce LuUw== 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=tT5meck62edPAXqkrlpPpDOqpQK+sSQS+PF+xhnQppI=; b=FN64Noc9Y5o5LA/5n2Wt8VJiBp2AfYFY4Ep8xa/YwmysPLgvP3Y1I+BdEmURSO45HL UHcF4q/avSpppWpp7dN25K4KczpFs3xXL8KRF2ynlDL0QE2vhbmHpKjZ39F5MpglL2FT bxH9ZxzcQd3Tuz15zWKplx9qkC+RYpBsgW0VxqydtNwCEl/CFnU7djIlTabl7kLy0YF9 hOtBM+nkp7y9yzp241couk5+KL2Yt0uht1upPNEOyY9OCTrQgXiAoHbq0yeBEJJ/jwCd qyB0t4e7dpAyYCP03MM93vA2iBZRpY/TPQWkcaRiSUbZpztdJv9LY2D4UDQovfsh3jyG AYOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=an6Slgp7; 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 q23-v6si3845770pgl.275.2018.07.18.09.35.28; Wed, 18 Jul 2018 09:35:43 -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=an6Slgp7; 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 S1731549AbeGRRMw (ORCPT + 99 others); Wed, 18 Jul 2018 13:12:52 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:37298 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731297AbeGRRMw (ORCPT ); Wed, 18 Jul 2018 13:12:52 -0400 Received: by mail-wm0-f68.google.com with SMTP id a19-v6so3524259wmb.2 for ; Wed, 18 Jul 2018 09:34:09 -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=tT5meck62edPAXqkrlpPpDOqpQK+sSQS+PF+xhnQppI=; b=an6Slgp7LjXF32GKoQLCXYqFCQluNM+x0KEyxoJP+fhuLZ6yC26vLInHAlyjnyYmP1 a0ce14ITVUPAKPfIGmwbU0iTBDFHzlSx0KHDmQQrGWodCHDPXZVDBEz5qkIFV5qeyOSb 5ovwRU9B4ntUjpM98JgeaWxQihldvwa6Kjvag= 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=tT5meck62edPAXqkrlpPpDOqpQK+sSQS+PF+xhnQppI=; b=mRCJxoksyuSxJEpZhBhi0ueNEdyI7BdEVrfKvUJFFiQBtU5HakNdP+e5Ma1Zhta04S yCtFdQQLxhO8esMgiX45H1sNchgLhrmze3IlIG3Ul9P7jJ+Y6PU6gfuAM0gEnC/3ApO4 bJMsnfwNcwOdHqbj/k86i+Jk4w88r8q2QBl+yrM/vSiubGWkiy5Yu8rgJSx7nORG3OHX LIL220xmOxV5hvDWIXQWr5jgW66axVZniyMS2QvBxWHptnTCrWtIa0aThsczuPAXQHUz boRmsNmePlVEj/ad1CC+xZRIUQG89UcIsbPxivO8iYeqXKqoDSSHMWurBI1jChpNu7ZB lHSQ== X-Gm-Message-State: AOUpUlGNbrUWF6NKTVTMr97ugZZfZDBysg2Pwh2rB9lCZ3ggcubvziln QYPApfraBhJVd2afnPfByWlJAw== X-Received: by 2002:a1c:58cb:: with SMTP id m194-v6mr2216820wmb.64.1531931648936; Wed, 18 Jul 2018 09:34:08 -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 q14-v6sm4150729wmd.20.2018.07.18.09.34.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jul 2018 09:34:07 -0700 (PDT) Date: Wed, 18 Jul 2018 17:34:05 +0100 From: Daniel Thompson To: Lee Jones Cc: Marcel Ziswiler , "linux-kernel@vger.kernel.org" , "jingoohan1@gmail.com" , "linux-pwm@vger.kernel.org" , "linux-fbdev@vger.kernel.org" , "b.zolnierkie@samsung.com" , "thierry.reding@gmail.com" , "dri-devel@lists.freedesktop.org" , "patches@linaro.org" Subject: Re: [PATCH] backlight: pwm_bl: Fix uninitialized variable Message-ID: <20180718163405.mnebf57apzvm276w@holly.lan> References: <20180716210241.9457-1-daniel.thompson@linaro.org> <20180718080913.GB4641@dell> <1531902119.16896.13.camel@toradex.com> <20180718095335.GD4641@dell> <20180718101227.shqf54wpt4kdrsj2@holly.lan> <1531918626.16896.22.camel@toradex.com> <20180718130853.GE4641@dell> <20180718134103.bgwpgk7l6joxtjoa@holly.lan> <20180718155544.GF4641@dell> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180718155544.GF4641@dell> User-Agent: NeoMutt/20180622 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 04:55:44PM +0100, Lee Jones wrote: > On Wed, 18 Jul 2018, Daniel Thompson wrote: > > > On Wed, Jul 18, 2018 at 02:08:53PM +0100, Lee Jones wrote: > > > > > > > No, then we are back to the initial issue of num_steps > > > > > > > potentially not > > > > > > > being initialised. We really want both of_property_read_u32() to > > > > > > > succeed AND num_steps to actually be set. > > > > > > > > > > > > I also think num_steps should be pre-initialised. > > > > > > > > Yes, I guess it definitely does not hurt. > > > > > > > > > > Then it will only be set if of_property_read_u32() succeeds. > > > > > > > > Yes, but we still need to check for both, the function not failing and > > > > num_steps to actually be non zero. > > > > > > Why? You don't do anything differently if it fails. > > > > Only if you initialize num_steps... > > > > We should either initialize to zero and not worry about the return > > code[1] or we check the return code and not worry about > > initialization[2]. I don't think both are worthwhile. > > > > Whilst initialization can fix this specific instance we generally avoid > > overusing it since it messes up static analysis and, in this instance, > > distance from declaration to use is >25 lines, hence current patchset. > > > > > > Daniel. > > > > > > [1] https://lkml.org/lkml/2018/7/16/399 > > [2] https://lkml.org/lkml/2018/7/16/1042 > > > > Or... > > > > We check the return code and leave number > > > > num_steps is uninitialized and stack allocated so it only has a valid > > value if of_property_read_u32() succeeds. > > > > We can (and I originally did) fix the bug by initializing num_steps to 0 > > but its quite some distance between declaration and use so I accepted > > Marcel's counter proposal to check the return code instead. > > Only checking the return value of of_property_read_u32() is also > suitable. I did think about that case... I concluded that it isn't wrong for a DT to set to this property to 0 (effectively meaning "no interpolated steps please"). If we take the branch when num_steps is zero we get a bunch of pointless housekeeping that amounts to no more than an extremely elaborate malloc/memcpy/free. Daniel.