From: Jonathan Cameron <jic23@kernel.org>
To: Petre Rodan <petre.rodan@subdimension.ro>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Angel Iglesias <ang.iglesiasg@gmail.com>,
Matti Vaittinen <mazziesaccount@gmail.com>,
Andreas Klinger <ak@it-klinger.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Subject: Re: [PATCH v3 2/2] iio: pressure: driver for Honeywell HSC/SSC series pressure sensors
Date: Mon, 4 Dec 2023 11:46:23 +0000 [thread overview]
Message-ID: <20231204114623.3aaa98d2@jic23-huawei> (raw)
In-Reply-To: <ZWtU836_yYWgMYZp@sunspire>
On Sat, 2 Dec 2023 18:01:55 +0200
Petre Rodan <petre.rodan@subdimension.ro> wrote:
> Hello!
>
> On Fri, Dec 01, 2023 at 06:24:53PM +0000, Jonathan Cameron wrote:
> > > > > +static int hsc_spi_probe(struct spi_device *spi)
> > > > > +{
> > > > > + struct iio_dev *indio_dev;
> > > > > + struct hsc_data *hsc;
> > > > > + struct device *dev = &spi->dev;
> > > > > +
> > > > > + indio_dev = devm_iio_device_alloc(dev, sizeof(*hsc));
> > > > > + if (!indio_dev)
> > > > > + return -ENOMEM;
> > > > > +
> > > > > + hsc = iio_priv(indio_dev);
> > > > > + hsc->xfer = hsc_spi_xfer;
> > > >
> > > > Also, pass the callback and spi->dev into hsc probe. Easy to use
> > > > a container_of() to get back to the struct spi_device *spi
> > >
> > > I'd rather simply pass along the client struct.
> > >
> >
> > I don't like the fact it has to be a void *
> >
> > The core code has no idea what is in there. At least we constraint it
> > somewhat with a struct device.
>
> but ...
> that is the nice part. the core code never needs to know what exactly is behind
> that pointer, since it only gets used by the i2c/spi module that provided that
> pointer in the first place. I've never seen a better use of void * :)
>
> I could define a
>
> struct client_handle;
>
> in the .h, use a pointer to that that as function argument, do a lot of
> castings, but I feel like it's still a void * with extra steps.
Usual trick for this is either use struct device and container_of or
an anonymous union wrapped up in a struct.
struct hsc_client_handle {
union {
struct i2c_client *i2c_client;
struct spithingy *spi_client;
};
};
Then assign appropriate element and pass the containing struct around.
No casting needed.
Aim is to define it as a constrained type that can only take one or the other of
the types in the union.
Jonathan
>
> cheers,
> peter
>
prev parent reply other threads:[~2023-12-04 11:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-26 10:27 [PATCH v3 2/2] iio: pressure: driver for Honeywell HSC/SSC series pressure sensors Petre Rodan
2023-11-26 13:58 ` kernel test robot
2023-11-26 18:33 ` Jonathan Cameron
2023-11-28 14:32 ` Petre Rodan
2023-12-01 18:24 ` Jonathan Cameron
2023-12-02 16:01 ` Petre Rodan
2023-12-04 11:46 ` Jonathan Cameron [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231204114623.3aaa98d2@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@Huawei.com \
--cc=ak@it-klinger.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ang.iglesiasg@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=petre.rodan@subdimension.ro \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox