From patchwork Tue Oct 22 13:43:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zicheng Qu X-Patchwork-Id: 13845728 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 0B78145945; Tue, 22 Oct 2024 13:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729605262; cv=none; b=jzeccl266UuGHV0hJsMcPlWb9PqWLkdV6TpA9hRb7V+afzlW17jE/uSpBxUzI1sOUU0M/yLaW0zeEP5SuIw6zpM9yULkHe1F0LeIo7pZ7AillCBgBbAmKJAGRhMnHo/C1LW5dS0r0p5WJjOmrf+s5IQfQuaZ7U8ExPSqe+HJXws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729605262; c=relaxed/simple; bh=fov3MOMN4MVn5VReFQzMvMLjhpAOIGW0maeN2pNlE/w=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WJEA5azh1nOb6H8a2P70CrG9nJ0FfEkJp299twZECBg3B3xgzNRCdO/lYTiYq63SDR1ipzKayPK/h6A7lxfeME5rKo0Iq5jqcAPX9yAVzEM2Qg7y84ymftj/dyCDNL3NUezZYQfJqpXRAinLjsd8aUIkQd9Kvn/qcSSMnKjFo3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XXtsH1S2dzpX5J; Tue, 22 Oct 2024 21:52:19 +0800 (CST) Received: from kwepemd200012.china.huawei.com (unknown [7.221.188.145]) by mail.maildlp.com (Postfix) with ESMTPS id 5934B18007C; Tue, 22 Oct 2024 21:54:16 +0800 (CST) Received: from huawei.com (10.67.175.84) by kwepemd200012.china.huawei.com (7.221.188.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 22 Oct 2024 21:54:15 +0800 From: Zicheng Qu To: , , , , , CC: , , , Subject: [PATCH] drivers/iio/adc/ad7124.c: fix division by zero in ad7124_set_channel_odr() Date: Tue, 22 Oct 2024 13:43:30 +0000 Message-ID: <20241022134330.574601-1-quzicheng@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200012.china.huawei.com (7.221.188.145) In the ad7124_write_raw() function, parameter val can potentially be zero. This may lead to a division by zero when DIV_ROUND_CLOSEST() is called within ad7124_set_channel_odr(). The ad7124_write_raw() function is invoked through the sequence: iio_write_channel_raw() -> iio_write_channel_attribute() -> iio_channel_write(), with no checks in place to ensure val is non-zero. Cc: stable@vger.kernel.org Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels") Signed-off-by: Zicheng Qu Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7124.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index a5d91933f505..b79c48d46ccc 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -637,7 +637,7 @@ static int ad7124_write_raw(struct iio_dev *indio_dev, switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: - if (val2 != 0) { + if (val2 != 0 || val == 0) { ret = -EINVAL; break; }