Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5506106imm; Mon, 23 Jul 2018 00:26:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdEx/bGLDniys6N4nK6qtp8KxYHaQ3kUDEvGULtH6yo/HC/liN9dyy5+0fXUB4nKuoWFFRX X-Received: by 2002:a17:902:8f86:: with SMTP id z6-v6mr11848488plo.38.1532330815575; Mon, 23 Jul 2018 00:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532330815; cv=none; d=google.com; s=arc-20160816; b=Dtj/IgTScDQnFU9k0L4ZnS3n6cCVipYZ9HSUaSWQg/VI8jpVK3lcpMKnBoePulM1hY Oii77Bez0AYx8Mv1zxza7OujoaWe4dq/Cp79bb/3kTu2KEHyCEYakW8e6aWY23c9x/4s AeBQkwETx8Sc3ctqMiTYyzv36s+YdolmRrmXkSllIYk7EzYnaUPqjR/7TPP08ph10uFh +ZJXhVVwRoCB4wJpv8wITG0p8KtPIqJ6hQ6yPVjvHF0R98JT45u1amy12VAXKK+VfHEx U1Wvgo77WveheV5hIwahx41G1S2/wW9rHwQTmO4pNJWzXpLpfScRNJIy90ExYd2D3Gsw cYTw== 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=MF/n2xMLCWrhcUKLxt9ix7TBuP+xciXlmLqLMilLFFs=; b=qFAO0RiP7Bvo2mI/MSQl8ExKbJXvl/6DhE/w6sbcEiN5yg9AJAoIhgvK3lCp9WszTd JcGluKkImBbxbu0kuJ23eNj4/xbWyc4Z7vv3CD96wtnR5qrRAnYU8F6EwXcN41Nb8zvu u3VE341cXCBa7Bwq5rOp5bRfvjahyfKSC7krVWXbxnWW9LoDpSKHXj5bPtNNv9JgFLlM Glh4mih5yonrPXtJrJoZcERDIqenm7Nc0D/jDVhj4WJftyPm2ct4l5Mn8TPmRmX0V6HV YXmP9/dBDOfhiJ56R3ha65Ii2DXMzGkkwqTMcUNbaSp6Z03KlSuLwHBQFP/702kLXT4x gfyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QIL4QrJX; 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 u11-v6si8093586pgg.683.2018.07.23.00.26.41; Mon, 23 Jul 2018 00:26:55 -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=QIL4QrJX; 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 S2388071AbeGWIZ2 (ORCPT + 99 others); Mon, 23 Jul 2018 04:25:28 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41346 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387869AbeGWIZ1 (ORCPT ); Mon, 23 Jul 2018 04:25:27 -0400 Received: by mail-wr1-f68.google.com with SMTP id j5-v6so16787300wrr.8 for ; Mon, 23 Jul 2018 00:25:37 -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=MF/n2xMLCWrhcUKLxt9ix7TBuP+xciXlmLqLMilLFFs=; b=QIL4QrJXIgTM0lTnCY/7vbUQXuN5wMsiPbhmuoJWLbU8uCooPTlnCAGIbBseFohp1+ q0S4kF/W1WhtqBcnYmML5xlQ3biaycLGzdPRmvsu7JtTOcygheazF5SW5OrixAbUDE5M C3w35QHMB9dDcDMYlnM79W7uUbHstG1vcnHeM= 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=MF/n2xMLCWrhcUKLxt9ix7TBuP+xciXlmLqLMilLFFs=; b=qr7JcMyvG9jl/Bl881kSVOlUP0lSQBjTMvNr7JksSwpNvXLQzAD4lzUiJ0LDnJM0u3 X6vf6QzsX9DqV9crLZ2X/6SEubbbS0E3K4Zv0NO2uc92/V3FNTYI+rZ6bnKDp3Of/N6S IeooWVxLzqtJCSP7Jfs3uBfCUztTfr4tKujViW/4cpUj111F8MwlmGa++f4AV04YMlB1 w2elCdeMl1wO0jotRljOh3pPwpNsEdP8y4I/X5T9lZMD6puxxKNkyQPy6uUrXXDeJWOt VB1BhatGW+03Bp3hCzclrSqLZuvZH5eLXdztzqAgo06ejRwsxyRLKnIWUDClNFmXgScy vq4w== X-Gm-Message-State: AOUpUlFPCwdQkiBkKcMu8GA4ow3oNw2wT838AL6HspF+PD6C3UPdPXy/ yB3QM6ffBwLmd5d5EXWiOLl1rGlJrXo= X-Received: by 2002:adf:bb08:: with SMTP id r8-v6mr7272879wrg.244.1532330736660; Mon, 23 Jul 2018 00:25:36 -0700 (PDT) Received: from dell ([2a02:c7d:1faf:e900:9403:d00:d6f3:4419]) by smtp.gmail.com with ESMTPSA id y11-v6sm6393525wrr.84.2018.07.23.00.25.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 00:25:35 -0700 (PDT) Date: Mon, 23 Jul 2018 08:25:34 +0100 From: Lee Jones To: Daniel Thompson 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: <20180723072534.GE4213@dell> 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> <20180718163405.mnebf57apzvm276w@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180718163405.mnebf57apzvm276w@holly.lan> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Jul 2018, Daniel Thompson wrote: > 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. Yet in the latest patch, you do it anyway? Or have I misread it? -- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog