From patchwork Thu Feb 22 06:14:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13566762 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 782FC16439 for ; Thu, 22 Feb 2024 06:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582473; cv=none; b=FvP/kPfSE51UcQyk4F7qcTneJ/6tjasqtohgKE+1Xjxjab2Jrsu4jY+L4kL0cadMpLwXqycYCbXTQlmT5dAVgrD/EOJ3M/yNOGO3DaoPYuPBqq0tbbb/ykEmaX/bK6zk+u4AooyIiZ7LlzCnnNS0EL98lu/Uxet1QXlOMSdEr+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582473; c=relaxed/simple; bh=eronbDz8hniFpG4P8U1NjCuXIc5mT2H0q1+vHe4QvZ0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=qfDJz5Ya1ZkZywoDqmhwxflAxGWgcVaoFuDOnv9TLQ4XuAOcBSX+gvFuBAHz5NI7rKtWDvgOEyPQFznr8K7gh6QYVfiudgbldry2tze5de/jGWVCCAKlplllMyCHrFvfUep9Q9q7iJt6iwWKzm+0rBfSb6npydtpE5evQl54Umo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tqHv6mvb; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tqHv6mvb" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fd72f7125so10478805e9.1 for ; Wed, 21 Feb 2024 22:14:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708582469; x=1709187269; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ihJpziOlMuDcSvTLuJ/gU0Hae3a368M+b9HMO37f99A=; b=tqHv6mvbEQESR6TN0fWmiYp95YTLBbXV0HW/8XpTFbJokG75u9vku9tiZy+qEmaEDn m0UnFrKessgtla2iX1TVY8SK7qMJidIjCCqFoXFuyEHy6DvVJHS67Os2QGUmdRwA1+7R V8aBXwezYOGqQ/Vhg2Ynf9lTvYqWcuSM5S4TssexsqHBZ6ZbMWm0pgL9T3jjlj1+vWQo ZqG7hcZ20xlxcq8shbXZkw/ZT9vhsUgEsu2a/Zs/25/U28F2lAE676BJDi+3kgi2aFtL OwJFBy0fWUE80TdxrWsDO9xj7qU6dkorGxglyV7DsoorOZD3Km07LQTgCIIiMPZcmISm LjUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708582469; x=1709187269; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ihJpziOlMuDcSvTLuJ/gU0Hae3a368M+b9HMO37f99A=; b=foBLdw2QdKVwIZfLZskw7w3G0YgptLp9JKxrQK5ERu+3pUClXQwMr4AO2I1rSiDRDx uvzISBTLJX9PLvf+peMIUFyhkhX0OpMjB/TGpnXmSQWvELQRidhipl2uwQ/SLec3W23C cLfGPweEaoVPa0VFX7DRgop7guK0sDJ06cFbgTDVLbcVXtlLyoUq6YatPFE/4ULAU6Q2 zGe3y7v4wcLttanz8X4kYT7UmrtIza1kZCuTQKfpAnjyulhAgYr22cqOJp7u88sJ/Y3w K7HkPg8K+1aLiuNv6EA8eiA+MVY82OWRuUe1C/P7HVG40977bCTG8pi7OjfdPZSSkCEU M7RA== X-Forwarded-Encrypted: i=1; AJvYcCVf7ObETl/LTCV6/kpB4OGu0h8UsdINOj2Hzule4VwRhzpePMHx+mMm9FfpJkwt07Qngmv3dX8GvlS+OoF/NCi7xX4aaWr8znLf X-Gm-Message-State: AOJu0YyD1QhPqhI9o0j8gTMhYLBWzIXIdGAsIgnBeajrnpX2Z86wKScb HSG7RYPKaSY87X3VAZUqAtnIKVTvqXJr8zh1QmFyHi0SFtV2Mw+LUFPAl+5s0wc= X-Google-Smtp-Source: AGHT+IGopM8CATzEXKdXm/OXCkYnC4ug5JZs7YcBQ+FJg2FL6Lca7YApWQZuoAl0Xt1vK64K14teSg== X-Received: by 2002:adf:ea82:0:b0:33d:29d3:1aa2 with SMTP id s2-20020adfea82000000b0033d29d31aa2mr8014703wrm.12.1708582469338; Wed, 21 Feb 2024 22:14:29 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id cc18-20020a5d5c12000000b0033d67791dc0sm8215530wrb.43.2024.02.21.22.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 22:14:29 -0800 (PST) Date: Thu, 22 Feb 2024 09:14:25 +0300 From: Dan Carpenter To: Mike Looijmans Cc: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Dan Carpenter , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/2] iio: adc: ti-ads1298: Fix error code in probe() Message-ID: <5f393a87-ca8b-4e68-a6f4-a79f75a91ccb@moroto.mountain> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding There is a copy and paste bug here, it should be "reg_vref" instead of "reg_avdd". The "priv->reg_avdd" variable is zero so it ends up returning success. Fixes: 00ef7708fa60 ("iio: adc: ti-ads1298: Add driver") Signed-off-by: Dan Carpenter Acked-by: Mike Looijmans --- drivers/iio/adc/ti-ads1298.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/ti-ads1298.c b/drivers/iio/adc/ti-ads1298.c index ed895a30beed..67637f1abdc7 100644 --- a/drivers/iio/adc/ti-ads1298.c +++ b/drivers/iio/adc/ti-ads1298.c @@ -657,7 +657,7 @@ static int ads1298_probe(struct spi_device *spi) priv->reg_vref = devm_regulator_get_optional(dev, "vref"); if (IS_ERR(priv->reg_vref)) { if (PTR_ERR(priv->reg_vref) != -ENODEV) - return dev_err_probe(dev, PTR_ERR(priv->reg_avdd), + return dev_err_probe(dev, PTR_ERR(priv->reg_vref), "Failed to get vref regulator\n"); priv->reg_vref = NULL; From patchwork Thu Feb 22 06:15:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13566763 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 688F1156DD for ; Thu, 22 Feb 2024 06:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582544; cv=none; b=De8qyny9CCa4+Db5wewR+MJWSn0OUlQwdcKgEVvRZry5hJKzHyP9minOtYALemxNdhaaMZAwJn+vj89BTJn9OXX3FTprFsQekiwsycAAUSk1E2SjN1xzsT1NXP6neOMh7ZdhvGMV/8MLHZEg/1p77TX5mI9GagP3P0i48S3JAC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582544; c=relaxed/simple; bh=147XQMUnoCd0ClmleOOh7y1eD/64PzMzGWzhpazFC88=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Sv2tOcIB77swHfUCanLObeLbAbWZM7Jh3UOrOytBTjG/jjQaY2oJXNJZehYj/qJ9XiSnfJpvmRMH1oSDjVUFhHIYrHe7YoW2+l4qrFLC7atYISv5xkudjrZOGzHrc2C+bkJ/wj4lt2bsoFiCp4zJM6URyxFRI7TciCE31aL4IlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=qg2ioOhL; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qg2ioOhL" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-33d146737e6so4893552f8f.0 for ; Wed, 21 Feb 2024 22:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708582541; x=1709187341; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Keqkv8FCF48d/7NwrtNWQmmyXMR6yDkcE3iXVzsS2CA=; b=qg2ioOhLej8VBFYG6bIWCEblbou+E52U52LwnKmtW2qTcpapzvgG1uQB4Y+RkgzyJ3 PLadEONcWamJgVK1IV6ZdCAkK3Vv9qvlF0QHnDXKTB6fDxNCDo1eg1x2vtaxrqupt3TJ mjzGqLfezcu3iOrBFJXOGi2zLS9DMS4JSiYkMPi8v7EKvlw+YmwOOlcKoWs8A3NqSVTo FQIISwwGed2DdWijc6GBem4jExxTn3uYxRof8f0+hmhDoH2JhgJ5LeaUaWiKe+vvNLUe ECCqsou/VeUV9Yv68V3SE/7spSt8yEmOUXK9jMMKXUM879QY4AFU0e3216OkSFl4vEe2 cT+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708582541; x=1709187341; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Keqkv8FCF48d/7NwrtNWQmmyXMR6yDkcE3iXVzsS2CA=; b=k/pDSXA/rxY/rH09/WHyxqUj94ZMZ6nkmsnFoUPvnY368QNtD0xFgtHVfNyWe4W/80 OGR4IlKddf60tZ7r07M7TzwbHc4BkXCPRxSXgBzrd3ofXPSrEAz4NTBVXGOnApWEHK2U ywzid1oLFPza5BZNGH9nw4KZdUj2Rf9R6cFAOv7Gldim5sDmx1QOAmXEOASa4Dp9Hv23 K73vm7zogQDQZVil8vFAikdU1f9V6PcE5CN3eruNmV8XSGc0LTMx6E1Csy+84wyVtFzX weZRgEJG3ABHbqG2eFLPeCAI9ui8ZPbCvb6e+N7pdMGZXLF66HDDRPv6vwtUbM8h+KN0 6L3g== X-Forwarded-Encrypted: i=1; AJvYcCUWVPPD232V7I4stwh55oY1yI6LcHZCwFe5RU2oIM1KOF+IK6jdkhf4tec4acALZtp4N9ejgkayfRm0Hl1Z6foNvxxGdpTSZZR7 X-Gm-Message-State: AOJu0YwwHM+OfD8XqeSVk/jswoAbSojciWmZXG8tiJuFNJRUwdturPaj mtlZmVPGAUBtz14ddCiTPeX8XrYKthuoBjuYsJGfe9C3ZVqVhyL0GZrtEJScQDE= X-Google-Smtp-Source: AGHT+IEN1UoorI8CvmFW/dCEroCtCwikt6G8NDq8DdZrsxY6xE2pIDqISjVhUBQtJyyfXAYziU/APg== X-Received: by 2002:a5d:51d1:0:b0:33d:6554:e1f9 with SMTP id n17-20020a5d51d1000000b0033d6554e1f9mr4738440wrv.50.1708582540814; Wed, 21 Feb 2024 22:15:40 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id o18-20020adfcf12000000b0033b87c2725csm19183702wrj.104.2024.02.21.22.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 22:15:40 -0800 (PST) Date: Thu, 22 Feb 2024 09:15:37 +0300 From: Dan Carpenter To: Mike Looijmans Cc: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 2/2] iio: adc: ti-ads1298: prevent divide by zero in ads1298_set_samp_freq() Message-ID: Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5f393a87-ca8b-4e68-a6f4-a79f75a91ccb@moroto.mountain> X-Mailer: git-send-email haha only kidding The "val" variable comes from the user so we need to ensure that it's not zero. In fact, all negative values are invalid as well. Add a check for that. Fixes: 00ef7708fa60 ("iio: adc: ti-ads1298: Add driver") Signed-off-by: Dan Carpenter --- I wrote this commit message in a very confident tone of voice and I have spent a long time looking at this code so I'm reasonably sure this patch is correct. However, I'm not super familiar with this subsystem so probably you should double check. drivers/iio/adc/ti-ads1298.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/adc/ti-ads1298.c b/drivers/iio/adc/ti-ads1298.c index 67637f1abdc7..1d1eaba3d6d1 100644 --- a/drivers/iio/adc/ti-ads1298.c +++ b/drivers/iio/adc/ti-ads1298.c @@ -258,6 +258,8 @@ static int ads1298_set_samp_freq(struct ads1298_private *priv, int val) rate = ADS1298_CLK_RATE_HZ; if (!rate) return -EINVAL; + if (val <= 0) + return -EINVAL; factor = (rate >> ADS1298_SHIFT_DR_HR) / val; if (factor >= BIT(ADS1298_SHIFT_DR_LP))