From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3C77C7618D for ; Tue, 14 Mar 2023 21:29:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjCNV27 (ORCPT ); Tue, 14 Mar 2023 17:28:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbjCNV26 (ORCPT ); Tue, 14 Mar 2023 17:28:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7301DB95; Tue, 14 Mar 2023 14:28:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA821619BF; Tue, 14 Mar 2023 21:28:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDF4FC433EF; Tue, 14 Mar 2023 21:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678829335; bh=3Xd2e0C4tHRKY8ttLfie/FTu756NF/DDGLIrwdbnRRI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CrnDapEVZAWiB+mIBAkjNiEv+UGUzEaAXzuMjTzjjEjS1jbpzhk4J2kgwl2c/1DLv leWLICG1I34rVaMoFzfS6KT+pDfSKjYUqn/qV27H2Izlzusu/PM9ELuMcVuZs5nbXc wiMQ4j/DZZzvknkfWI0XjEcLTr5fvjiRHDqDdIO5S4sbCsFW3ae6cixo9DDsOymiU4 xdm60qcKIRC2XZyRwIRkMQXETXv9NIYJCA7kkOswpKDjc6IIqXKiE3zulc8GtuzLRV fDyJUISdqsbDYK0sZx473KQnK7GIf7PFS+sV5De4ORUzdhJqHaLlzq6JpuHDtE5tuF wO2ZHOvbLsEtg== Date: Tue, 14 Mar 2023 22:28:51 +0100 From: Andi Shyti To: Linus Walleij Cc: Kasumov Ruslan , Andy Gross , Bjorn Andersson , Konrad Dybcio , Jonathan Cameron , Lars-Peter Clausen , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Kasumov Ruslan Subject: Re: [PATCH] iio: adc: qcom-pm8xxx-xoadc: Remove useless condition in pm8xxx_xoadc_parse_channel() Message-ID: <20230314212851.hqbzs5hhed5apcv5@intel.intel> References: <20230314193709.15208-1-xhxgldhlpfy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Hi, > > The left side of the loop condition never becomes false. > > hwchan cannot be NULL, because it points to elements of the > > hw_channels array that takes one of 4 predefined values: > > pm8018_xoadc_channels, pm8038_xoadc_channels, > > pm8058_xoadc_channels, pm8921_xoadc_channels. > > > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > I am not impressed with that tool. See below: > > > Fixes: 63c3ecd946d4 ("iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC") > > Signed-off-by: Kasumov Ruslan > > (...) > > hwchan = &hw_channels[0]; > > - while (hwchan && hwchan->datasheet_name) { > > + while (hwchan->datasheet_name) { > > if (hwchan->pre_scale_mux == pre_scale_mux && > > hwchan->amux_channel == amux_channel) > > break; > > NAK have you tested this on a real system? > > Here is the complete loop: > > hwchan = &hw_channels[0]; > while (hwchan && hwchan->datasheet_name) { > if (hwchan->pre_scale_mux == pre_scale_mux && > hwchan->amux_channel == amux_channel) > break; > hwchan++; ops, yes, sorry, I overlooked at this... This becomes NULL at some point as there is a sentinel in the _variant structures. Thanks, Andi > chid++; > } > > Notice how hwchan is used as iterator in hwchan++. > > What you are doing will cause a zero-pointer dereference. > > Whoever is developing "SVACE" needs to fix the tool to understand > this kind of usage. > > Yours, > Linus Walleij