lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20231204114623.3aaa98d2@jic23-huawei>
Date:   Mon, 4 Dec 2023 11:46:23 +0000
From:   Jonathan Cameron <jic23@...nel.org>
To:     Petre Rodan <petre.rodan@...dimension.ro>
Cc:     Jonathan Cameron <Jonathan.Cameron@...wei.com>,
        linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
        Lars-Peter Clausen <lars@...afoo.de>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Angel Iglesias <ang.iglesiasg@...il.com>,
        Matti Vaittinen <mazziesaccount@...il.com>,
        Andreas Klinger <ak@...klinger.de>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>
Subject: Re: [PATCH v3 2/2] iio: pressure: driver for Honeywell HSC/SSC
 series pressure sensors

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ