libsrp, srp_target_alloc() and srp_target_free()
Hello,
There is an asymmetry between the libsrp functions srp_target_alloc() and srp_target_free(): the former sets the pointer to driver-private data by invoking dev_set_drvdata() while the latter does not clear this pointer. So once srp_target_free() finished invoking dev_get_drvdata() will return a dangling pointer. Would it be a good idea to add the following statement inside srp_target_free() just before this function returns ?
dev_set_drvdata(target->dev, NULL);
Bart.
Quoted 9 lines · On Sun, 6 Dec 2009 11:18:13 +0100 Bart Van Assche <[email protected]>…
There is an asymmetry between the libsrp functions
srp_target_alloc()andsrp_target_free(): the former sets the pointer to driver-private data by invokingdev_set_drvdata()while the latter does not clear this pointer. So oncesrp_target_free()finished invokingdev_get_drvdata()will return a dangling pointer. Would it be a good idea to add the following statement insidesrp_target_free()just before this function returns ?
dev_set_drvdata(target->dev, NULL);
It's fine by me but I don't see any point.
For me, it's pretty clear that you can't use a pointer to something after freeing it.
struct srp_target *target;
target = dev_get_drvdata(&dev->dev);srp_target_free(target);
Then you want to do something like?
target = dev_get_drvdata(&dev->dev);