From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795043906; b=E+sFQxQBlhKWWN+4ervech26IZxyA0krAopBmYqKIS1FPnjVR/o6d/f5G9jtBXZo1cuM oMgPUF0x1KefnwCeZx3EDK4mi2fVj9z3wqnrx6PGPFUab/wwFwm5Qx8MXUn/4m/3fIiXN 5u18R2mN4f2TM7wGkvjusmWEMpWm9Tp+f9m0/8HGtQFjdoqXO5YSGhok7JPsGboR4il2W v9X0qzed/HnKMPFDqdTFRdpnCXcl0Es7Q7SAOjkv2P1HRglwOg5QIRBmdgcF61/n3mmxa Q3NXxiL0z6gZW1BWpO+Ms376mACu0m4A/Y76UbEWfcX1++Fr6kBBoverlr/xxukMsdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795043906; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=jAKyF/HYI8YnwWQhTpaEovxJn2jeu2f3RQwX42wk6HU=; b=wdgdOqvfOUj1eZelFju1+Jvc5UsUmX3gzysdFYQscxlMPAtP3eZ+Q2I9elTL5LzJBLo4 wi8K1VfC9JB0PhBP6AkrxCvXAkK6Ks1aNAo5MjKSS3ujxtpzy9ZV42pRNm6QcAy/M7asf R8QhQsRLEVxYN0Ow+ZxPVqoMobHjfrkWJFqQtLKpr2bpCDUli9nh9jOZgnZFBJ9l8oH4X fmxq091f410L5qmNvqBfOW6sH23y+B6H7h6cBgNESX6DUJGatbJuFqFD4m8ZrT3X36H1r eV0McmpDE0Pz6WncvgLbsqt9ZkpvXasPk2vFfhCbdZsNlyMUzlNT4Old23NoNyZZxnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=reltixpl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFFDA606A325; Wed, 18 Nov 2026 23:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=reltixpl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CE371F000C4; Wed, 18 Nov 2026 23:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795043906; bh=jAKyF/HYI8YnwWQhTpaEovxJn2jeu2f3RQwX42wk6HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=reltixplCsDzUtxOStrVM7mmTSwnvQV0B1+aaqSIJnlsw5VcUphnRwT7/tWAeEUr2 zouKZMQl7WZ7gVuPuVnWHPe7K0Zk3U8XxUD5CZLhpfA6eRwh/6aJE6WhKj+mfRULN0 zKGfT8r9mW0Ac9bGQFvwBraoryoVOXeOWJwLxsWs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Lechner , Nuno Sa , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.1 0379/2857] iio: buffer: use struct iio_scan_type to simplify code Date: Wed, 18 Nov 2026 15:23:33 +0100 Message-ID: <20261118150215.051299726@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Lechner [ Upstream commit 7758562898033a3bd98a24d2a541c930b0fc98e6 ] By using struct iio_scan_type, we can simplify the code by removing lots of duplicate pointer dereferences. This make the code a bit easier to read. This also prepares for a future where channels may have more than one scan_type. Signed-off-by: David Lechner Reviewed-by: Nuno Sa Link: https://lore.kernel.org/r/20240530-iio-add-support-for-multiple-scan-types-v3-2-cbc4acea2cfa@baylibre.com Signed-off-by: Jonathan Cameron Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler") Signed-off-by: Sasha Levin --- drivers/iio/industrialio-buffer.c | 48 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 37ea4a2d85f85..87ab3266d0925 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -367,7 +367,8 @@ static ssize_t iio_show_fixed_type(struct device *dev, char *buf) { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - u8 type = this_attr->c->scan_type.endianness; + const struct iio_scan_type *scan_type = &this_attr->c->scan_type; + u8 type = scan_type->endianness; if (type == IIO_CPU) { #ifdef __LITTLE_ENDIAN @@ -376,21 +377,21 @@ static ssize_t iio_show_fixed_type(struct device *dev, type = IIO_BE; #endif } - if (this_attr->c->scan_type.repeat > 1) + if (scan_type->repeat > 1) return sysfs_emit(buf, "%s:%c%d/%dX%d>>%u\n", iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.repeat, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->repeat, + scan_type->shift); else return sysfs_emit(buf, "%s:%c%d/%d>>%u\n", iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->shift); } static ssize_t iio_scan_el_show(struct device *dev, @@ -686,12 +687,16 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev, unsigned int scan_index) { const struct iio_chan_spec *ch; + const struct iio_scan_type *scan_type; unsigned int bytes; ch = iio_find_channel_from_si(indio_dev, scan_index); - bytes = ch->scan_type.storagebits / 8; - if (ch->scan_type.repeat > 1) - bytes *= ch->scan_type.repeat; + scan_type = &ch->scan_type; + bytes = scan_type->storagebits / 8; + + if (scan_type->repeat > 1) + bytes *= scan_type->repeat; + return bytes; } @@ -1623,18 +1628,21 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, if (channels) { /* new magic */ for (i = 0; i < indio_dev->num_channels; i++) { + const struct iio_scan_type *scan_type; + if (channels[i].scan_index < 0) continue; + scan_type = &channels[i].scan_type; + /* Verify that sample bits fit into storage */ - if (channels[i].scan_type.storagebits < - channels[i].scan_type.realbits + - channels[i].scan_type.shift) { + if (scan_type->storagebits < + scan_type->realbits + scan_type->shift) { dev_err(&indio_dev->dev, "Channel %d storagebits (%d) < shifted realbits (%d + %d)\n", - i, channels[i].scan_type.storagebits, - channels[i].scan_type.realbits, - channels[i].scan_type.shift); + i, scan_type->storagebits, + scan_type->realbits, + scan_type->shift); ret = -EINVAL; goto error_cleanup_dynamic; } -- 2.53.0