On Sat, 2 Dec 2023 18:01:55 +0200 Petre Rodan <petre.rodan@xxxxxxxxxxxxxxx> 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 >