drivers/iio/proximity/mb1232.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
Use a stack allocated struct for the scan data instead of using the
driver state to store the struct. The scan data is not used outside of
the interrupt handler function so the struct does not need to exist
outside of that scope.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/proximity/mb1232.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/proximity/mb1232.c b/drivers/iio/proximity/mb1232.c
index 01783486bc7df34ec3b38b1d0ad5f52e3eae6c92..34b49c54e68b0a11bac0287c65cb368c9e956da4 100644
--- a/drivers/iio/proximity/mb1232.c
+++ b/drivers/iio/proximity/mb1232.c
@@ -42,11 +42,6 @@ struct mb1232_data {
*/
struct completion ranging;
int irqnr;
- /* Ensure correct alignment of data to push to IIO buffer */
- struct {
- s16 distance;
- aligned_s64 ts;
- } scan;
};
static irqreturn_t mb1232_handle_irq(int irq, void *dev_id)
@@ -120,12 +115,16 @@ static irqreturn_t mb1232_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct mb1232_data *data = iio_priv(indio_dev);
+ struct {
+ s16 distance;
+ aligned_s64 ts;
+ } scan = { };
- data->scan.distance = mb1232_read_distance(data);
- if (data->scan.distance < 0)
+ scan.distance = mb1232_read_distance(data);
+ if (scan.distance < 0)
goto err;
- iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+ iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan),
pf->timestamp);
err:
---
base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
change-id: 20250722-iio-proximity-mb1232-use-stack-allocated-scan-struct-e0f051595dfe
Best regards,
--
David Lechner <dlechner@baylibre.com>
On Tue, 22 Jul 2025 17:39:17 -0500 David Lechner <dlechner@baylibre.com> wrote: > Use a stack allocated struct for the scan data instead of using the > driver state to store the struct. The scan data is not used outside of > the interrupt handler function so the struct does not need to exist > outside of that scope. > > Signed-off-by: David Lechner <dlechner@baylibre.com> Hi David, Applied to the testing branch of iio.git. I don't suppose you fancy a follow up to take that irqnr local to probe? If not I'll get to it at some point maybe. Thanks, Jonathan > --- > drivers/iio/proximity/mb1232.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > > diff --git a/drivers/iio/proximity/mb1232.c b/drivers/iio/proximity/mb1232.c > index 01783486bc7df34ec3b38b1d0ad5f52e3eae6c92..34b49c54e68b0a11bac0287c65cb368c9e956da4 100644 > --- a/drivers/iio/proximity/mb1232.c > +++ b/drivers/iio/proximity/mb1232.c > @@ -42,11 +42,6 @@ struct mb1232_data { > */ > struct completion ranging; > int irqnr; > - /* Ensure correct alignment of data to push to IIO buffer */ > - struct { > - s16 distance; > - aligned_s64 ts; > - } scan; > }; > > static irqreturn_t mb1232_handle_irq(int irq, void *dev_id) > @@ -120,12 +115,16 @@ static irqreturn_t mb1232_trigger_handler(int irq, void *p) > struct iio_poll_func *pf = p; > struct iio_dev *indio_dev = pf->indio_dev; > struct mb1232_data *data = iio_priv(indio_dev); > + struct { > + s16 distance; > + aligned_s64 ts; > + } scan = { }; > > - data->scan.distance = mb1232_read_distance(data); > - if (data->scan.distance < 0) > + scan.distance = mb1232_read_distance(data); > + if (scan.distance < 0) > goto err; > > - iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), > + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), > pf->timestamp); > > err: > > --- > base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446 > change-id: 20250722-iio-proximity-mb1232-use-stack-allocated-scan-struct-e0f051595dfe > > Best regards,
On 7/24/25 5:26 AM, Jonathan Cameron wrote: > On Tue, 22 Jul 2025 17:39:17 -0500 > David Lechner <dlechner@baylibre.com> wrote: > >> Use a stack allocated struct for the scan data instead of using the >> driver state to store the struct. The scan data is not used outside of >> the interrupt handler function so the struct does not need to exist >> outside of that scope. >> >> Signed-off-by: David Lechner <dlechner@baylibre.com> > Hi David, > > Applied to the testing branch of iio.git. > > I don't suppose you fancy a follow up to take that irqnr local to probe? > If not I'll get to it at some point maybe. > It is also used in mb1232_read_distance(), so this wouldn't be trivial.
On Fri, 5 Sep 2025 14:12:49 -0500 David Lechner <dlechner@baylibre.com> wrote: > On 7/24/25 5:26 AM, Jonathan Cameron wrote: > > On Tue, 22 Jul 2025 17:39:17 -0500 > > David Lechner <dlechner@baylibre.com> wrote: > > > >> Use a stack allocated struct for the scan data instead of using the > >> driver state to store the struct. The scan data is not used outside of > >> the interrupt handler function so the struct does not need to exist > >> outside of that scope. > >> > >> Signed-off-by: David Lechner <dlechner@baylibre.com> > > Hi David, > > > > Applied to the testing branch of iio.git. > > > > I don't suppose you fancy a follow up to take that irqnr local to probe? > > If not I'll get to it at some point maybe. > > > It is also used in mb1232_read_distance(), so this wouldn't be trivial. Ah. I'd missed that. Agreed that it doesn't makes sense to make it local. J
© 2016 - 2025 Red Hat, Inc.