Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1068254lqd; Thu, 25 Apr 2024 05:23:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrlqLCqYaCSlqLwaNsSCxgeqkwdLdC+AOpy8riMNq9358l2Ez+7O1hIpJQQQMNU6xUSESDeIulYwEyJP0D5LKpVDnJqv4KGOgadpO+3w== X-Google-Smtp-Source: AGHT+IFqAYZ2/McN0bugZ7exKu7ZYiSk25sRExrzEAWlTDfk30AyCI7vkBEhKskw2/3n71MbkmqE X-Received: by 2002:a0c:fc4b:0:b0:6a0:a279:8e87 with SMTP id w11-20020a0cfc4b000000b006a0a2798e87mr1320500qvp.3.1714047795707; Thu, 25 Apr 2024 05:23:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714047795; cv=pass; d=google.com; s=arc-20160816; b=KIj2NRO1GURpHQh7JWDtoKEaJwevctRkHO2GX69tzZb8COOlmuyR81xypT9eN+yXzU kiCgVdfXeVq3J/Jyas30dtLWdxwL4iyQnvVZu0/njvTPDndtE/wESm2/2VWN6GPNmbVk yyXNgOgK3dKPJN8VRPcjm1W5h8+vyTl1OjcP0n1LDSeOLmkv/78Xv/iDPnI4192/IQGk 9UnEwDQyqP74AH/d1y+3r9jmdNUmM7qEk336G9dzRir7yhFXaibBw5D1mgCz+XBVfGGd mCJKhrbjy3yzxlwmWe7fyz9gU7AtZrF/4+LT+VhB+B+fRKTimNMWcTOtkUeRCXQEcoDn wMdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aL/Z6pF/77qKHPDv3jImi+JhTRuduLaERCMWgedJTqk=; fh=II1UhLDS0TXYfmGXPA5HFp5SbyOSQMawPTfaT6Qg33I=; b=EiOd3TVyB8u2LWK6FOV+BpYiVOnfgyaF9PrFeL7ndrSa3jqQkcOzxA0Inujbykol3c JqdOA/c3gF7xSoxqMVzNZnr178kwNrVCG07gYWyEZ+kmUtqcHvf/Yz8gYFfZCGWE/i+2 EIvpZL/nDPDV9byjasjtk/uiMLRa+cIVgDBpwGmJJ9JM8fIkUYi9rTMv95my34V6GxzB zIQa/Uluj9igaWo5PSknpZ/yv1CRfyx8RD07gTbcfZAm2BhoWa02WltfFi7WNuh/B6/h +4JbBl5Vr6Cr6aRtNEOOJzpARwYRi0oXk3Tigln7SYgzcSl2GLKEqTtpEmA7ep4DluaL UDSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=jD9FAo4h; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-158514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158514-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jm5-20020ad45ec5000000b0069b503c0f35si17625817qvb.600.2024.04.25.05.23.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 05:23:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=jD9FAo4h; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-158514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158514-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6E1C41C21EEE for ; Thu, 25 Apr 2024 12:23:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C353012C460; Thu, 25 Apr 2024 12:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="jD9FAo4h" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 0515E12AAC5; Thu, 25 Apr 2024 12:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714047788; cv=none; b=OLtSgtuIyqzIf/9eVP+lrHfgqoX0aueT14fCQLAa8YcY/lNtb6lTkizR2Q7bUlD+tXRA1EU1b7X4HLROyoQUQTloFfNtrOEbA9111bDX+Tk4j3SIuYA0ZG59gL6Q4fPOjGwqmXA7G1RcGz3ue4wLKFqNn6hqHyN60Ek+X5VKtdE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714047788; c=relaxed/simple; bh=ka9MBV9PeSymXBRhhYYBWCDmGPWgFkeaY09SK+d3rqE=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ulQWB9nvTUzjhcqyP/8+/AGfY1Or0cQLASByMRQmJKgTZk2sA5HHnsRyX+nEIk632uGYR9K453SfQvYJQaNH7nziCEuFw+NgawZrRbAgSM/KMKBKNZ3DRd1Xfur4/ptUl1uW5AI4hA/7InhB8QiXBZjpSFwohgCh7JTABpdd+xM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=jD9FAo4h; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1714047788; x=1745583788; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ka9MBV9PeSymXBRhhYYBWCDmGPWgFkeaY09SK+d3rqE=; b=jD9FAo4h3WPnuoerVaXpgmugjccqXcoARjvRgo8grPMOhHh6B90vMYsk Lq7f+oUpi/sbQQJ782mbJhFGvF8S0aH5zEhS8KfFHULwKtVOAbJkO2aFt Pq2idJL/rs0Es2YRKphkrZKoV/6hcfNZgcyRqK64JH5mtcDBcv4fmaUSC nXTP4FXIkeHnhWbTsTqgjKaO4Ckp2FSyqRCCkfxRouoB+O1wAmtI+ufrJ 62WqC7YWM/sPmjFQtam34KKXiN3/ho0sDZbuNZPWJwkvNMvSNHY/WdVlp o0ud4zmbPJFKlq2QHLj7dzzYu0D2aVhtiBTI9xzZL6P6aOSE+uV4DZJpA g==; X-CSE-ConnectionGUID: wwZCvykgROeJ0FlGisTKvw== X-CSE-MsgGUID: uqF8t8JRR8qapq0V2oh2pA== X-IronPort-AV: E=Sophos;i="6.07,229,1708412400"; d="asc'?scan'208";a="22628058" X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Apr 2024 05:23:06 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 25 Apr 2024 05:23:03 -0700 Received: from wendy (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Thu, 25 Apr 2024 05:23:01 -0700 Date: Thu, 25 Apr 2024 13:22:45 +0100 From: Conor Dooley To: CC: , , , , , , Subject: Re: [PATCH v1] iio: adc: PAC1934: fix accessing out of bounds array index Message-ID: <20240425-canteen-alias-5a907b1deecc@wendy> References: <20240425114232.81390-1-marius.cristea@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1EW7HVGbh5br5EAU" Content-Disposition: inline In-Reply-To: <20240425114232.81390-1-marius.cristea@microchip.com> --1EW7HVGbh5br5EAU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 25, 2024 at 02:42:32PM +0300, marius.cristea@microchip.com wrot= e: > From: Marius Cristea >=20 > 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. >=20 > Fixes: 0fb528c8255b: "iio: adc: adding support for PAC193x" > Reported-by: Conor Dooley > Signed-off-by: Marius Cristea > --- > drivers/iio/adc/pac1934.c | 9 +++++++++ > 1 file changed, 9 insertions(+) >=20 > 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_de= v, > s64 curr_energy; > int ret, channel =3D chan->channel - 1; > =20 > + /* > + * 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 >=3D PAC1934_MAX_NUM_CHANNELS) > + channel =3D channel - PAC1934_MAX_NUM_CHANNELS; > + > ret =3D pac1934_retrieve_data(info, PAC1934_MIN_UPDATE_WAIT_TIME_US); > if (ret < 0) > return ret; >=20 > base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91 > --=20 > 2.34.1 >=20 --1EW7HVGbh5br5EAU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZipLFQAKCRB4tDGHoIJi 0qv8AP9sDEguR1KU2sc68ldF+YJPVrg4I1a3EynhdNA89mydgwD/Wb9FRgx20W02 QfTkKi1SgkK8AVqcjXUEUkbim7PBNQQ= =6QRm -----END PGP SIGNATURE----- --1EW7HVGbh5br5EAU--