Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM / OPP: Add reference counting helpers for Rust implementation

To ensure that resources such as OPP tables or OPP nodes are not freed
while in use by the Rust implementation, it is necessary to increment
their reference count from Rust code.

This commit introduces a new helper function,
dev_pm_opp_get_opp_table_ref(), to increment the reference count of an
OPP table and declares the existing helper dev_pm_opp_get() in pm_opp.h.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

+18 -6
+12 -5
drivers/opp/core.c
··· 1528 1528 return ERR_PTR(ret); 1529 1529 } 1530 1530 1531 - void _get_opp_table_kref(struct opp_table *opp_table) 1532 - { 1533 - kref_get(&opp_table->kref); 1534 - } 1535 - 1536 1531 static struct opp_table *_update_opp_table_clk(struct device *dev, 1537 1532 struct opp_table *opp_table, 1538 1533 bool getclk) ··· 1688 1693 kfree(opp_table); 1689 1694 } 1690 1695 1696 + void _get_opp_table_kref(struct opp_table *opp_table) 1697 + { 1698 + kref_get(&opp_table->kref); 1699 + } 1700 + 1701 + void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) 1702 + { 1703 + _get_opp_table_kref(opp_table); 1704 + } 1705 + EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref); 1706 + 1691 1707 void dev_pm_opp_put_opp_table(struct opp_table *opp_table) 1692 1708 { 1693 1709 kref_put_mutex(&opp_table->kref, _opp_table_kref_release, ··· 1733 1727 { 1734 1728 kref_get(&opp->kref); 1735 1729 } 1730 + EXPORT_SYMBOL_GPL(dev_pm_opp_get); 1736 1731 1737 1732 void dev_pm_opp_put(struct dev_pm_opp *opp) 1738 1733 {
-1
drivers/opp/opp.h
··· 250 250 }; 251 251 252 252 /* Routines internal to opp core */ 253 - void dev_pm_opp_get(struct dev_pm_opp *opp); 254 253 bool _opp_remove_all_static(struct opp_table *opp_table); 255 254 void _get_opp_table_kref(struct opp_table *opp_table); 256 255 int _get_opp_count(struct opp_table *opp_table);
+6
include/linux/pm_opp.h
··· 100 100 #if defined(CONFIG_PM_OPP) 101 101 102 102 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); 103 + void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table); 103 104 void dev_pm_opp_put_opp_table(struct opp_table *opp_table); 104 105 105 106 unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index); ··· 161 160 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, 162 161 unsigned int *bw, int index); 163 162 163 + void dev_pm_opp_get(struct dev_pm_opp *opp); 164 164 void dev_pm_opp_put(struct dev_pm_opp *opp); 165 165 166 166 int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp); ··· 206 204 { 207 205 return ERR_PTR(-EOPNOTSUPP); 208 206 } 207 + 208 + static inline void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) {} 209 209 210 210 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} 211 211 ··· 344 340 { 345 341 return ERR_PTR(-EOPNOTSUPP); 346 342 } 343 + 344 + static inline void dev_pm_opp_get(struct dev_pm_opp *opp) {} 347 345 348 346 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} 349 347