Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp836874lqa; Sun, 28 Apr 2024 06:32:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWS1WzbQGp8KUTYH6tgLBWZUBBLxTJVx2tfYc9X7Y9YMoPHmlerNvNsdiPddwJljhSZefTMaB57zRTGkH5P2u1V5RNKRom48sWF5plRA== X-Google-Smtp-Source: AGHT+IEzX01O/A5NTwN2jVJ512jgeL4ZbrJsjqttE12t1IGYcIKPjD5fky3ROZ0SCFjmFji+ZArr X-Received: by 2002:a92:cdad:0:b0:36c:4b9d:7d8d with SMTP id g13-20020a92cdad000000b0036c4b9d7d8dmr1447938ild.15.1714311174464; Sun, 28 Apr 2024 06:32:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714311174; cv=pass; d=google.com; s=arc-20160816; b=Tts4BaCOmw9bvs7fecKIzQJZR0MXi0u+dw89Z3yGRIAvPYJwmr5KuFRVO6Hu5ANntX U7++qmDDyoj1Zvb3lYlet2++MB5mB3cFzq7R70+CcdnbfJ6RFnKyR4g39OxF4fm9FJtm 1pvbwZVTDlTglmA56Uu+k3rhD5gxQWR9ILVB8SNwCYmoOcW9xwwk/cvL+NXAVi4oRwdE nrQdPgTV1L2btF0AZ9hTts5k95o09lGWlZ6GZ1ssbkk90Ne089OKt8jddwbZHtqFvcZL Xj8ScJmgUBmY3erNBdD10c9fAkRwD/nE8PcKgUGCQ06q4a2IAHn2jbmwJcj2A0jzACxA 4I5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Zh2VfXjhyZFZikEn6hdVRPZi2XUOAC0sRX/GVVAfHAU=; fh=8VRTOR1uU8nQvklqa9+Bj44OXJQhIFQD2rsMgsKWVAg=; b=aiuf24VVXDpLRFE5T/9bu32rdQUI0jKY4lhNoesiADnWL31BLxsEHmVh9EYAiXoDnv Tt/l/uhpNCD4fuzuQ42nkQaC0M9AHfIee49sqr19XdFx24A1usJK1qUVmPWzkfvA22A2 C5cKz5o4YsWL4A8656DR52qN3yLoy/L9TXvQm3NXLa4ti/RUe8l3OsdIxSkdfua9Ug7y un5Xr04nO+E5c63zIAnP/1SKprjR6dIdiCokhbfLT1WrPpod8Es3AMjjYK9Io1Wf1dTj O59UC2EaSYdRvX9X6BdB6Klr1n33Z+OLqusa969R8UPpusOgA8QqmNnxH3cJg1Xyutei VTSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SfjuQ0Z5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161440-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161440-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s2-20020a634502000000b0060763d02db1si7452170pga.611.2024.04.28.06.32.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 06:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161440-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SfjuQ0Z5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161440-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161440-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4FD38B2134F for ; Sun, 28 Apr 2024 13:32:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F0AC6E61E; Sun, 28 Apr 2024 13:32:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SfjuQ0Z5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6A40F516; Sun, 28 Apr 2024 13:32:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714311147; cv=none; b=cVQfT8g4yG8Fh+fBKqw63Wu31HRh32iuWJQ9PQBJKmYYXeQf8sHdGLhA9vF5JwpPFmZungKsKyNHLG5xK5bov5giGA4qyAcN+dpOnNaMyxbCCaCy0AI301vzqKYhkhVwTIpGOX72XivZKkXsRdbXMiuc5awFWulwPmuNHWC1iXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714311147; c=relaxed/simple; bh=DpW/WuXrLhtm2ZKRngLmSo7dhMhjdfQekX2EAKWeMXM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lXlrl8bLSwyT5mFHvxPbLoi6vJHY5gcUF/w1qMI8AvA3sI1nVr8Cklk3AhrQv9A5XuY8kmaQkKFjIvcrpSYq2Vs19dl+oo4R+RQ3UfTVAhZlETjhLe9aS1Ntl/fKvOP9AtB0KshCSaJ5QtpilJ+p/Sxz9PtYAnkEyRpD4jKQvMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SfjuQ0Z5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DD39C113CC; Sun, 28 Apr 2024 13:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714311147; bh=DpW/WuXrLhtm2ZKRngLmSo7dhMhjdfQekX2EAKWeMXM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SfjuQ0Z5+q3Ohqyg/hpbGu/B5Bkmr6r99A6SRFj7OeMzzBZCezPPuhnvKvjyKw7iC SZwQ/zlRKeJF6frW9kQ6sGnh9PPnL4GRMuQ88hHgRWYpdU6fi6Rd1v1FbmOoI6HYSe QlVbYISjLNNHisUuLIbSc8p9XFU4x/8bLlvL5z45v1TUjFG3KrKXe4DxoIDKu53BxF gyUCqvtMiQ80yDlBeaCzF+kE0VCK7Sxs6VgIhKJNTIq9+bE9D/j2ZkDbjrYGwZRMMb ee6gWl5EzNH5y2CM7A6FoEptUabwnJmBBwoF7RAKhgb/c0yp6gsI8RUWPqQETSHESi WXvRvPOlKaCtQ== Date: Sun, 28 Apr 2024 14:32:15 +0100 From: Jonathan Cameron To: Conor Dooley Cc: Conor Dooley , marius.cristea@microchip.com, lars@metafoo.de, lgirdwood@gmail.com, broonie@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org Subject: Re: [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index Message-ID: <20240428143215.3388426d@jic23-huawei> In-Reply-To: <20240425-vastly-salad-e56b9225e662@spud> References: <20240425114232.81390-1-marius.cristea@microchip.com> <20240425-canteen-alias-5a907b1deecc@wendy> <20240425-vastly-salad-e56b9225e662@spud> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 25 Apr 2024 16:36:19 +0100 Conor Dooley wrote: > On Thu, Apr 25, 2024 at 01:22:45PM +0100, Conor Dooley wrote: > > On Thu, Apr 25, 2024 at 02:42:32PM +0300, marius.cristea@microchip.com wrote: > > > From: Marius Cristea > > > > > > Fix accessing out of bounds array index for average > > > current and voltage measurements. The device itself has > > > only 4 channels, but in sysfs there are "fake" > > > channels for the average voltages and currents too. > > > > > > Fixes: 0fb528c8255b: "iio: adc: adding support for PAC193x" > > > Reported-by: Conor Dooley > > > Signed-off-by: Marius Cristea > > > Huh, this is an empty message. I intended to send some tags, but must > not have saved the buffer. > > Closes: https://lore.kernel.org/linux-iio/20240405-embellish-bonnet-ab5f10560d93@wendy/ > Tested-by: Conor Dooley Applied to the fixes-togreg branch of iio.git Thanks, Jonathan > > Cheers, > Conor. > > > > --- > > > drivers/iio/adc/pac1934.c | 9 +++++++++ > > > 1 file changed, 9 insertions(+) > > > > > > diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c > > > index f751260605e4..456f12faa348 100644 > > > --- a/drivers/iio/adc/pac1934.c > > > +++ b/drivers/iio/adc/pac1934.c > > > @@ -787,6 +787,15 @@ static int pac1934_read_raw(struct iio_dev *indio_dev, > > > s64 curr_energy; > > > int ret, channel = chan->channel - 1; > > > > > > + /* > > > + * For AVG the index should be between 5 to 8. > > > + * To calculate PAC1934_CH_VOLTAGE_AVERAGE, > > > + * respectively PAC1934_CH_CURRENT real index, we need > > > + * to remove the added offset (PAC1934_MAX_NUM_CHANNELS). > > > + */ > > > + if (channel >= PAC1934_MAX_NUM_CHANNELS) > > > + channel = channel - PAC1934_MAX_NUM_CHANNELS; > > > + > > > ret = pac1934_retrieve_data(info, PAC1934_MIN_UPDATE_WAIT_TIME_US); > > > if (ret < 0) > > > return ret; > > > > > > base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91 > > > -- > > > 2.34.1 > > > > >