Skip to contentSkip to conversation

libsrp, srp_target_alloc() and srp_target_free()

DISCUSSION Bart Van Assche 2 participants 2 messages Dec 6, 2009 – Dec 7, 2009 SCSI

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw
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() 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);

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);