On Tue, Jun 29, 2021 at 07:32:36PM +0800, Bing Fan wrote: > hello, > > replied as below. > > and new patch is at the bottom. Please submit this properly as the documentation says to do so, I can't take an attachment :( > > > + struct amba_device *amba_dev = (struct amba_device *)uap->port.dev; > > Are you sure you can just cast this like this? Did you test this? > > > Yes, i have tested and applied in my project. > > The function pl011_probe calls pl011_setup_port with &amba_dev->dev and uap > params; > > and pl011_setup_port set uap->port.dev to the address of amba_dev->dev; > > the two structs' relationship is: > > struct amba_device { > > struct device dev; > > …… > > }; > > When pointer(uap->port.dev) points to amba_dev->dev address, the momery > actully stores > > content of struct amba_device; so the cast assignment can be forced to > amba_dev. That is now how this should work, use the correct container_of() cast instead. That will always work no matter where struct device is in the structure. You got lucky here :) > > > + > > > + if (!amba_dev) > > > + return -1; > > Do not make up error numbers, return a specific -ERR* value. > > changed to "return -ENODEV" So this changed the logic of this function, is that ok? > > > > And how can this happen? > > The function pl011_setup_port isn't called, event pl011_probe isn't called. And how can that ever happen? thanks, greg k-h