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: 204572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp61907dyb; Wed, 21 Feb 2024 22:15:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqIIwYQ8LM6t83vWBycjzd8Z29vC9Vgz/CnmhoA/h9VWE103Ea/+B4hKfS1dX02S7alk3L7DwenP5T0Wd36wwB5Qnw/w== X-Google-Smtp-Source: AGHT+IHxbTrt3EmPYez9UFScZEW0pzSZ3vf6SXS42QHs8ynkW2aZE+72cQN79Lw8jwEFdaPl4GEN X-Received: by 2002:a05:620a:8c9:b0:787:25e8:e604 with SMTP id z9-20020a05620a08c900b0078725e8e604mr18916932qkz.53.1708582559504; Wed, 21 Feb 2024 22:15:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708582559; cv=pass; d=google.com; s=arc-20160816; b=P/x0FS51gY7gEYl+crHGbFITYONci5WKAbLDf8PF9D8Xv6lriA4sqrOe9B963QWrb9 2aQUfZjrFxPfvgIVU41NqF5S4o5XA9mngIagGVnQ9OBPvr4yJkLH22L7wIs/e5KTbAmJ dJ8jVAArzMz7eQwMagLb7vPLJonj8x+UOmXo2IQ/2xDPCDpvgrR7VebSNqMcIAtvrvRX 66SgwAm1DQPxuH2iye1FLAoBCfZ6Yeu3Vu5+vtSTVaP80ezEmR4MG7TzPckHLd6h84aL O9IV8Rnxwrta9keTxr4RSFNoj7rXBii4GXu3DtqPhJJhs+65PJwTIVBfdQDWyhalrrC0 wa9A== 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:message-id:subject:cc:to:from :date:dkim-signature; bh=Keqkv8FCF48d/7NwrtNWQmmyXMR6yDkcE3iXVzsS2CA=; fh=Oa9iIj9GeEfvRmw2wJUXaXsUFrvioADWnXhHOnQQOnM=; b=q/w5SaSEPjT9A6BQEQ6C/ahhjH5fuXJN/4Xhgutocjaqknf3tehnMH2nsESfkoPqCb Kk8+mDoPXC5RmiLehxPpcfXCNAVMamsgUwj/MrZ8ogIkA1YN9+b4soqnWNo4rMN5yZwX F5ZLNTp1e3sUxhzjjcrTdNHSONNS9gcke//wWUhtHHXsb9BIMfYdg6yfiLd+6wnoPMEu V9ct/p/+tvDH40j2HMeZglCR27zWEDPFScudI3CEzDT14AHILGnN1cO9kpg03wnpeNGT 8gDZz9gi0SPVIq9afNnKiU0COfB/Zq+F8PJZ+4u1u8xNi32NXZQ0Q0YsAkiIC8tDASfr zvHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qg2ioOhL; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75975-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75975-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dv12-20020a05620a1b8c00b007879bd80e5dsi830343qkb.610.2024.02.21.22.15.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 22:15:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75975-ouuuleilei=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=@linaro.org header.s=google header.b=qg2ioOhL; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-75975-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75975-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 21D421C21325 for ; Thu, 22 Feb 2024 06:15:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B97AA179A4; Thu, 22 Feb 2024 06:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qg2ioOhL" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 65D061426A for ; Thu, 22 Feb 2024 06:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582545; cv=none; b=m35B1dYgGRKpg9ePwzIR8bxdEJVOhZQZuMoYd772qlEuUrZJ/W3uu2y8ZTiM26P5ba0qj9n20bThmAIsj6J5brVqjcIbiI02Cho14FtAniYRhI0r7gHuUpjVpLvKw39hF7eTZ4gQHlunnQUhmeZ2DTCPZSh3rhoK64ydx/ZxYRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708582545; c=relaxed/simple; bh=147XQMUnoCd0ClmleOOh7y1eD/64PzMzGWzhpazFC88=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=kKPDpBal5l/ZshCdiRcBT5T+jg6xemcYqBeiRfPPQR7VjJ1S1rOk1SGhKnvCLGiNaqBg0YARXN4SCryoubPmp1C4mR01H7Lx7sutYrQidKX31sDPNjMWT2cXGVBGBrRAwrsx7IojlUQ148sCQ4g0eU+RRzg0NLje2fDpaGELeAw= 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.41 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 Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33d38c9ca5bso2453558f8f.2 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=ZQGJMJbpKkFNYC4IeOVExYpkDYvRpZV4vwnxEuUnmkduWlXUCaPVKQJj4Xel1dOG2A FZWZe1QvV8smU6rtPkW7xugPWyUsp8tT+az86/a7ekCTUDnOjV+1MiC9tiFLRz0O4eMx u4pLVgkiEebAjX38oEktX/TRE6apY2H44TiMtvP7QNZyD5o2J9KgyCPZQNE5COpk7VmC iy41RiofBCukZ2KF2+pPrrfA0N5uFGGWZYr+lquJq8BVy4tqhjb2uBoASfWvDDQTqzEL 8A5RSNtTRn+M2/fDsxi9wkFZVRlxl1LbJqo6HpqAf8C0Bj0PCf7jQ1GQfTWK5Kop8PDi Jx9Q== X-Forwarded-Encrypted: i=1; AJvYcCXeLoVr/NPuEYlu4WF/T0i1CWyuS9rd9D3rhxjR07E7wekhKwLmBr9YimrtzyNj3DuZPCINke5AXBukF0G5vkq3wfBwiZJV6U+KpiY1 X-Gm-Message-State: AOJu0YxgDLeUBtYL3E2nyGjw3DrcBusDxrqUXfHQTHbPbIl0p/d0pqJI 5SK5qGiO2MdSKZpCiL5cpAzUXy5P0RPQgW/p2A/fWlOEAya+VsqGzuQDA6A0O4s= 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-kernel@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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791578665764563864 X-GMAIL-MSGID: 1791578665764563864 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))