Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1875735imm; Sat, 13 Oct 2018 05:45:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV61kvhvkr74UV5roOtTl1fRLjqHMC1uvoetiKWLJTTH35O3QxnizYlb2S4l9GzMQMIEtIVEW X-Received: by 2002:a62:384c:: with SMTP id f73-v6mr10112965pfa.242.1539434709960; Sat, 13 Oct 2018 05:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539434709; cv=none; d=google.com; s=arc-20160816; b=be7AaYCidTknJPpxNSeT+Hes0YRyBbjSC0EaWihzljdsVTb4Ue3epXiutf65oeNsRM 7se3aD11CoTSbMfb/eUSBtWbj0isFTCjbEYxc6J2F9zWxwzNwbuNXcHO8sRx/wo6Kn9t syK2Z+Hih2cmcA0oVNzKdk32f/EtvAvATp5No8nNbNtl6Fo6af3KR4mOVZjx+uV5vo14 5hB+eHUXyYcFq3FbIKDhaORQP9AEyfNX2VHK5CXUQK5+nxCljt4y+OFZWb8TfpU+D53W hjucV12innmr9E2SGPXcBrLxY+hqMtLH3lPQNMpCsFzCwUmSqWuqtfkKvGnPQfCZCC9y VEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=syHM/dtDJUuJ8FxAwYhNkGO4jw8V66uhmLy7akfZR30=; b=GzlGUlEEH4xSaJv+TMJAKK2V2E1W/ZluzjOhcvxUay6hc6cLHRlI2buODxLqB4voJx iOQuK+P/ixawnEXMjmUzWGJxIkBYuQT4gplT33LSpTQw6JhOixm+1o97UIv3TrqcnRev a/UMHsgY/+L4SpV66EXpDwkGj2jDEFr8mHNn6mu3lRXa8OvZ+JWkdqzfNRkbrJ451Sc6 34iRe2xcZQpQL0iZ9do6Cu0Bvb+T+djEIUUpmo+8zme8r22jd9ybeLbft/uzwr/781gS 6Y+yJOcTeL8qNpvJc1gzjG5F7F7lMmPGDlprCDlLXVJz4FaP7DpiFkRBRRtnUjAd8P5F pY1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ESD2DSa6; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si4424745pgd.528.2018.10.13.05.44.54; Sat, 13 Oct 2018 05:45:09 -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=@kernel.org header.s=default header.b=ESD2DSa6; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbeJMUVf (ORCPT + 99 others); Sat, 13 Oct 2018 16:21:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:57578 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeJMUVe (ORCPT ); Sat, 13 Oct 2018 16:21:34 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 723702087D; Sat, 13 Oct 2018 12:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539434673; bh=lXYRQgD8ZjR7fH9HqZwEt8Uws+QRb/vDnxbfn+n0C4s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ESD2DSa6X9rvSW3rIsrD+RO9ahnmQVP8/3L/PMs8X906ncjC5BmCOGDe6OyPRGhTH 41AdwdRXjvNZOnf0xZMuqpySp+6vxT9ffjUhs98GNW59pAeXEx5h7nCkGM8goiL8tW utbyLR+lX7aHqBHkYauxN2VII/gFQz6BwhZ1SkgQ= Date: Sat, 13 Oct 2018 13:44:29 +0100 From: Jonathan Cameron To: Stefan =?UTF-8?B?QnLDvG5z?= Cc: Colin King , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , , , Subject: Re: [PATCH] iio: adc: ina2xx: fix missing break statement Message-ID: <20181013134429.1f450ba7@archlinux> In-Reply-To: <1884341.stJYpOWv9L@pebbles> References: <20181008210904.9362-1-colin.king@canonical.com> <1884341.stJYpOWv9L@pebbles> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 Oct 2018 12:42:39 +0200 Stefan Br=C3=BCns wrote: > On Montag, 8. Oktober 2018 23:09:04 CEST Colin King wrote: > > From: Colin Ian King > >=20 > > The IIO_CHAN_INFO_SCALE case is missing a break statement and in > > the unlikely event that chan->address is not matched in the nested > > switch statement then the code falls through to the following > > IIO_CHAN_INFO_HARDWAREGAIN case. Fix this by adding the missing > > break. While we are fixing this, it's probably a good idea to > > add in a break statement to the IIO_CHAN_INFO_HARDWAREGAIN case > > too (this is a moot point). > >=20 > > Detected by CoverityScan, CID#1462408 ("Missing break in switch") =20 >=20 > Although it is good for code clarity to add a break statement, the code c= an=20 > never return anything but -EINVAL in case chan->address is not handled in= =20 > IIO_CHAN_INFO_SCALE: >=20 > ----- > switch (mask) { > case IIO_CHAN_INFO_SCALE: > switch (chan->address) { > case INA2XX_SHUNT_VOLTAGE: > ... return IIO_VAL_FRACTIONAL; > =20 > case INA2XX_BUS_VOLTAGE: > ... return IIO_VAL_FRACTIONAL; >=20 > case INA2XX_CURRENT: > ... return IIO_VAL_FRACTIONAL; >=20 > case INA2XX_POWER: > ... return IIO_VAL_FRACTIONAL; > } >=20 > case IIO_CHAN_INFO_HARDWAREGAIN: > switch (chan->address) { > case INA2XX_SHUNT_VOLTAGE: > ... return IIO_VAL_FRACTIONAL; > =20 > case INA2XX_BUS_VOLTAGE: > ... return IIO_VAL_INT; > } > } > return -EINVAL; > ----- >=20 > The addresses handled in INFO_HARDWAREGAIN is a subset of the ones in=20 > INFO_SCALE. >=20 > I would prefer an early "return -EINVAL" here, as it matches better with = the=20 > other "switch (mask)" cases above. >=20 > Kind regards, >=20 > Stefan I agree with Stefan on this. It is more in keeping with the local style to use a direct return. Colin, would you mind doing a v2 with that approach? If not I'll get to it at somepoint if no one else does, but it may take some time! Please also change the title to make it clear that this is beyond unlikely as I think it is impossible (without a gross bug somewhere else). This is worthwhile as an improvement to code clarity and false warning suppression, but it's not a fix I want to be pushed back to ancient kernels as in that circumstance it's really just noise. Jonathan >=20