From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 5C7AA3BE14D for ; Fri, 17 Jul 2026 16:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784306061; cv=none; b=j3oEgZiTclDkaqmW+23L9VwiC0x4CNSDZaERGzGv6j3EuSkuVDWdxRyPPNJL25exVT4jTJUxP9zm1tog8Hnpz7PqLZueoaPw8P0eunTXg4RKF+LGMcjnwM92vv3dTS58CZ7m4vd+iCINVUDTcoijJ4Czyd1SLATvfj1ndhRatYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784306061; c=relaxed/simple; bh=6wnDDJQBQfpjll1dAST5KuLlqAlQD+gfIzZDEDQKs6o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iL9bQn+lo8gfbX6Br23+0fP42XhqIhbjbPCJ84s2iyYfsszaz8QpeZOJ7u7HNl5UEaVXpH960b5GD7WcLNhIh3KLcxVpDPIq9Mznqxby/59SZEkRE2D/74fqqaD96C9RqBlNnAsHyjT28e+IzMBW5tVUfRunla2bC+uh2egPwUE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LetJwMu4; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LetJwMu4" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-81ef11a0972so10055807b3.1 for ; Fri, 17 Jul 2026 09:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784306056; x=1784910856; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=SN6iKB84XjlCdyQZDXiTIhq7M2trG088S3ZqcAJw8RI=; b=LetJwMu4heHGTkO9n0+tizadoIYlVjFv8exTgBmshyKjC07HVJ+polcD/CB531vB2A KWF9iCfpo0/qOS+NFk4aDL6Hr9cV1i5TDHPHZ1dpproD6FbcWopBaAqXMfxIuQ2UPQ9S T2+7oHMdeoiLCnjw+eJB+Va7Gw0ov2wCCC1S8/iUbT+ODf55IV2dLyQvdMUbWuu3UAK2 3xStBpkSevm2TAnyg8ASRtOkmNQJDovCS+lRpn5V8VWVuZCJFDTDMvh1P6hL/f8m2Qoj 8SknQvy23JyEa/VR+y5jpxqY4kv7V0WP6Vfb1utu6puMaWfjDwFmlSML+REx3o5KilRJ tzkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784306056; x=1784910856; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=SN6iKB84XjlCdyQZDXiTIhq7M2trG088S3ZqcAJw8RI=; b=V52KUge1skphpu1BTLtU6A7ODVBrYxFlPu54gCCUNaIEbpNspNVT1FX+saZSGU/6Zk 50k2tBtUIpT7HLJIMgk22gMlubU611GjHjZFqcUAke3jOepEoFdCjHjkqf98SiPrSwH/ 5j2bYcs9GBGDXNW3jp6BEBiSIt3NQ1ipMVCZzoYO6eGXzL3vKCMEMNtWu9aW6Svw5Q3T Lf21ee0EvhA2ClFAAa3R4jB8D9MCKbC+cpIDzNLsv9jNk8sdCWzdEWr1Hf0nJYyrYHNx rnetI8qtUauL4MNxev4t2StYMS166DxjdiypQ+wfT9DT25rv5aMdc/9dvXV+lEUXw/nL lgNQ== X-Forwarded-Encrypted: i=1; AHgh+RqRjM1srf9yZgNuHxVAwEmrUT3+7DhCu70I1yNfOhntatHZKhoIyj/VCvq7/znTfIifhOhLSF4PLHAz@vger.kernel.org X-Gm-Message-State: AOJu0YwA0rNMypaW1Uc216NEMuL8dPPIqROwlkazHw2iQ+VR4rFsYv6a jXTPRMbXP7rkignqh+UG5aBDordWaK0aUwzdsQbelriMSbwjhriLVoEK X-Gm-Gg: AfdE7cl2zaA6zq2xEFRsoKwnGrLlITjDEOJzGiWBhhkC3iis3nt56lHp9vetntOwFmT 1825YXI/yI/Xyu7VNaxWbdGB0b1RuotdsCzUC/WEZ4Fs7Z9xTC4bhm/y3US/i2jfFrnluAWhmis Nlujt2c+4htabi+FpftjZGQ6sWqNRZyDynA2EnPYvxpgSeMylu37te0grJ9EcePpHt0Ekmc9J2f vUubfHf8dZ9HVArKN+BQf+R6WWpPD7uuz9UeOjXmeRw9kBt8ATQb+cHCuP2URQlBbjgsEBlYDeW pYcqDZQF4GH5j/XOqDy35GyR9sTLxziE6jjoiVgLT1HYGZ7FywwSkBivyem07OF1o/MEbAT6JEK roRPqATL+oIAWIGXjlJZQh64MaUqmMAg5s9lixXlB9SfKC09abfBrhH1IA5XJAgOlCCSSnchSyI TCRzh8On8CNPY= X-Received: by 2002:a05:690c:6107:b0:81e:bbcd:f5c3 with SMTP id 00721157ae682-81ef25e16eamr11174017b3.36.1784306056131; Fri, 17 Jul 2026 09:34:16 -0700 (PDT) Received: from localhost ([2804:30c:1f09:b400:47f8:7933:2105:dd41]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81efe45416fsm53397b3.6.2026.07.17.09.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 09:34:14 -0700 (PDT) Date: Fri, 17 Jul 2026 13:35:14 -0300 From: Marcelo Schmitt To: sashiko-reviews@lists.linux.dev Cc: Marcelo Schmitt , robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, marcelo.schmitt1@gmail.com Subject: Re: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture Message-ID: References: <564b975c2c62d28ee6733f86bd5632c41a7c80e4.1784235595.git.marcelo.schmitt@analog.com> <20260716212451.923951F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260716212451.923951F000E9@smtp.kernel.org> On 07/16, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: > - [High] Integer divide-by-zero leading to kernel panic in `ltc2378_update_conversion_rate` when a sampling frequency of 1 Hz is requested and the PWM driver rounds the period length above 1 second. > -- > > --- Patch [3]: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture --- > commit ef54f2c79f2cac1649922032814adc7fcc5f9684 > Author: Marcelo Schmitt > Subject: iio: adc: ltc2378: Enable high-speed data capture > > This commit enables high-speed data capture for the ltc2378 ADC driver by > utilizing SPI transfer offloading. It allows data acquisition at faster sample > rates up to 2 MSPS. > > > diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c > > index 5600c820c7f45..7d29f021cb7b4 100644 > > --- a/drivers/iio/adc/ltc2378.c > > +++ b/drivers/iio/adc/ltc2378.c > > [ ... ] > > > + /* > > + * Configure SPI offload PWM trigger. > > + * The trigger should fire after tBUSYLH + tCONV + tDSDOBUSYL. > > + * Minimum time needed: TBUSYLH (13ns) + TCONV (part-specific) + TDSDOBUSYL (5ns) > > + * > > + * Use the same period as CNV PWM to avoid timing issues. > > + * Convert back from period to frequency for the SPI offload API. > > + */ > > + offload_period_ns = cnv_wf.period_length_ns; > > + config.periodic.frequency_hz = div_u64(HZ_PER_GHZ, offload_period_ns); > > + min_read_offset = LTC2378_TBUSYLH_NS + st->info->tconv_ns + LTC2378_TDSDOBUSYL_NS; > > + offload_offset_ns = min_read_offset; > > + count = 100; > > + do { > > + config.periodic.offset_ns = offload_offset_ns; > > + ret = spi_offload_trigger_validate(st->offload_trigger, &config); > > + if (ret) > > + return ret; > > + offload_offset_ns += 10; > > + } while (count-- && config.periodic.offset_ns < min_read_offset); > > + > > + /* Check the minimum CNV to SCLK delay is met */ > > + if (config.periodic.offset_ns < min_read_offset) > > + return -EDOM; > > + > > + /* Check the PWM periods remain the same */ > > + offload_period_ns = div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz); > > [Severity: High] > Could this result in a kernel panic due to an integer division by zero? > > If a user writes 1 to the IIO in_voltage_sampling_frequency sysfs attribute, > ltc2378_update_conversion_rate() is called with freq_Hz = 1, and the initial > requested PWM period is calculated as 1,000,000,000 ns. > > If the underlying hardware PWM driver rounds the period slightly upwards > (e.g., to 1,000,000,001 ns) during pwm_round_waveform_might_sleep() due to > clock granularity, offload_period_ns will exceed HZ_PER_GHZ. > > This causes config.periodic.frequency_hz = div_u64(HZ_PER_GHZ, offload_period_ns) > to evaluate to 0. > > When div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz) is subsequently called, > it divides by zero. If we have cnv_wf.period_length_ns == NSEC_PER_SEC + 1 after the offset_ns loop and config.periodic.frequency_hz == 0 as suggested, then spi_offload_trigger_validate() will fail the frequency_hz check and ltc2378_update_conversion_rate() errors out with -EINVAL before reaching div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz). https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-offload-trigger-pwm.c?h=v7.2-rc3#n48 > > > + if (cnv_wf.period_length_ns != offload_period_ns) > > + return -EDOM; > > + > > + st->offload_trigger_config = config; > > + st->cnv_wf = cnv_wf; > > + st->cnv_Hz = DIV_ROUND_CLOSEST_ULL(HZ_PER_GHZ, cnv_wf.period_length_ns); > > + > > + return 0; > > +} > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784235595.git.marcelo.schmitt@analog.com?part=3