Skip to content

Commit 2f3edc6

Browse files
committed
[SCSI] transport_class: BUG if we can't release the attribute container
Every current transport class calls transport_container_release but ignores the return value. This is catastrophic if it returns an error because the containers are part of a global list and the next action of almost every transport class is to free the memory used by the container. Fix this by making transport_container_release a void, but making it BUG if attribute_container_release returns an error ... this catches the root cause of a system panic much earlier. If we don't do this, we get an eventual BUG when the attribute container list notices the corruption caused by the freed memory it's still referencing. Also made attribute_container_release __must_check as a reminder. Cc: Greg KH <greg@kroah.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent fa8e36c commit 2f3edc6

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎drivers/base/transport_class.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ EXPORT_SYMBOL_GPL(anon_transport_class_register);
108108
*/
109109
void anon_transport_class_unregister(struct anon_transport_class *atc)
110110
{
111-
attribute_container_unregister(&atc->container);
111+
if (unlikely(attribute_container_unregister(&atc->container)))
112+
BUG();
112113
}
113114
EXPORT_SYMBOL_GPL(anon_transport_class_unregister);
114115

‎drivers/scsi/raid_class.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ raid_class_release(struct raid_template *r)
289289
{
290290
struct raid_internal *i = to_raid_internal(r);
291291

292-
attribute_container_unregister(&i->r.raid_attrs.ac);
292+
BUG_ON(attribute_container_unregister(&i->r.raid_attrs.ac));
293293

294294
kfree(i);
295295
}

‎include/linux/attribute_container.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ attribute_container_set_no_classdevs(struct attribute_container *atc)
3737
}
3838

3939
int attribute_container_register(struct attribute_container *cont);
40-
int attribute_container_unregister(struct attribute_container *cont);
40+
int __must_check attribute_container_unregister(struct attribute_container *cont);
4141
void attribute_container_create_device(struct device *dev,
4242
int (*fn)(struct attribute_container *,
4343
struct device *,

‎include/linux/transport_class.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ static inline int transport_container_register(struct transport_container *tc)
8686
return attribute_container_register(&tc->ac);
8787
}
8888

89-
static inline int transport_container_unregister(struct transport_container *tc)
89+
static inline void transport_container_unregister(struct transport_container *tc)
9090
{
91-
return attribute_container_unregister(&tc->ac);
91+
if (unlikely(attribute_container_unregister(&tc->ac)))
92+
BUG();
9293
}
9394

9495
int transport_class_register(struct transport_class *);

0 commit comments

Comments
 (0)