When class_dev_iter is initialized, the reference count for the subsys private structure is incremented, but never decremented, causing a memory leak over time. To resolve this, save off a pointer to the internal structure into the class_dev_iter structure and then when the iterator is finished, drop the reference count.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -74,6 +74,7 @@ struct class { · 73 unmodified lines | ||
| 74 | 74 | struct class_dev_iter { |
| 75 | 75 | struct klist_iter ki; |
| 76 | 76 | const struct device_type *type; |
| 77 | + struct subsys_private *sp; | |
| 77 | 78 | }; |
| 78 | 79 | |
| 79 | 80 | int __must_check class_register(const struct class *class); |