scsi: iscsi: Switch to using the new API kobj_to_dev()
PATCH 1/1 scsi: iscsi: Switch to using the new API kobj_to_dev()
Fix the following coccicheck warnings:
./drivers/scsi/scsi_transport_iscsi.c:930:60-61: WARNING opportunity for kobj_to_dev().
--- drivers/scsi/scsi_transport_iscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_iscsi.c +1 -1
@@ -927,7 +927,7 @@ static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj, struct attribute *attr, int i) { - struct device *dev = container_of(kobj, struct device, kobj); +struct device *dev =kobj_to_dev (kobj);struct iscsi_bus_flash_session *fnode_sess =iscsi_dev_to_flash_session (dev);struct iscsi_transport *t = fnode_sess->transport;
Signature · 1 line
1.8.3.1
Quoted 4 lines · Jiapeng Chong
Fix the following coccicheck warnings:
./drivers/scsi/scsi_transport_iscsi.c:930:60-61: WARNING opportunity for
kobj_to_dev().
I have to ask, what is the point of this? container_of is usually pretty safe ... as in it will detect when you screw up the usage. The only real misuse you can get is when the input type has an object of the same name and return type and you got confused between two objects with this property, but misuses like this resulting in bugs are very, very rare.
Usually we wrap container_of because the wrapping is a bit shorter as you can see: kobj_to_dev is about half the size of the container_of form ... but is there any other reason to do it?
The problem is that container_of is a standard way of doing cast outs in the kernel and we have hundreds of them. To be precise, in scsi alone:
jejb@jarvis:~/git/linux/drivers/scsi> git grep container_of|wc -l 496
So we really don't want to encourage wrapping them all because the churn would be unbelievable and the gain minute. So why should this one case especially be wrapped when we don't want to wrap the others?
James