Re: [PATCH v7 1/2] i2c: core: Add i2c_update_timeout() helper for dynamic transfer timeouts

Mukesh Savaliya <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-i2c
Message-ID <[email protected]>

On 8/13/2026 11:15 AM, Aniket Randive wrote:
[...]

> +void i2c_update_timeout(struct i2c_adapter *adap, u32 bus_freq_hz,
> +			size_t len, unsigned int safety_coeff,
> +			unsigned int min_usec)
> +{
> +	u64 bit_usec = mul_u64_u32_div(len * 9, USEC_PER_SEC, bus_freq_hz);
let's validate bus_freq_hz to prevent from 0 value in case of any 
abnormal caller.

> +	u64 total_usec = bit_usec * safety_coeff + min_usec;
> +	unsigned long jiffies_val;
> +
> +	/* Userspace-configured timeout always takes precedence. */
> +	if (adap->user_timeout > 0) {
> +		adap->timeout = adap->user_timeout;
> +		return;
> +	}
> +
> +	jiffies_val = usecs_to_jiffies((unsigned int)min_t(u64, total_usec, UINT_MAX));
> +	/* adap->timeout is int; guard against signed overflow. */
> +	adap->timeout = (int)min_t(unsigned long, jiffies_val, INT_MAX);
> +}
> +EXPORT_SYMBOL_GPL(i2c_update_timeout);
> +#endif /* CONFIG_I2C_DYNAMIC_TIMEOUT */
> +

[...]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.