Accessing a pdev or its members

Greg KH greg at kroah.com
Sat Sep 25 02:31:33 EDT 2021


On Fri, Sep 24, 2021 at 09:30:55PM -0500, Drew Abbott wrote:
> Hello all,
> 
> A third party driver has a probe function foo_probe(struct
> platform_device) that ends up allocating and initializing a list of
> various device structs:
> 
> struct device *dev = &pdev->dev;
> struct ucsi_dev *udev;
> udev = devm_kzalloc(dev, sizeof(*udev), GFP_KERNEL);
> /* initialize udev to important data */
> platform_set_drvdata(pdev, udev);
> 
> I have my own driver that I would like to use to access the *udev that
> is created when the other device is probed. How would I access a pdev?

You can not, it is not owned by your driver and the lifetime rules
should not give you access to it.

Why would you want to poke around in a platform device that is
controlled by a different driver?  What does your driver want to do?

> Or is there a way I can add a function to this driver to expose a
> *udev? I can't seem to get to it without having a pointer to the pdev,
> the udev, or some other device struct related to the hardware.

Why not move your functionality into the existing driver if you need to
talk to the same hardware device?

thanks,

greg k-h



More information about the Kernelnewbies mailing list