Skip to content

Commit b489e79

Browse files
committed
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 <[email protected]>
1 parent 1d38eb7 commit b489e79

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

drivers/opp/core.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,11 +1528,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index)
15281528
return ERR_PTR(ret);
15291529
}
15301530

1531-
void _get_opp_table_kref(struct opp_table *opp_table)
1532-
{
1533-
kref_get(&opp_table->kref);
1534-
}
1535-
15361531
static struct opp_table *_update_opp_table_clk(struct device *dev,
15371532
struct opp_table *opp_table,
15381533
bool getclk)
@@ -1693,6 +1688,17 @@ static void _opp_table_kref_release(struct kref *kref)
16931688
kfree(opp_table);
16941689
}
16951690

1691+
void _get_opp_table_kref(struct opp_table *opp_table)
1692+
{
1693+
kref_get(&opp_table->kref);
1694+
}
1695+
1696+
void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table)
1697+
{
1698+
_get_opp_table_kref(opp_table);
1699+
}
1700+
EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref);
1701+
16961702
void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
16971703
{
16981704
kref_put_mutex(&opp_table->kref, _opp_table_kref_release,
@@ -1727,6 +1733,7 @@ void dev_pm_opp_get(struct dev_pm_opp *opp)
17271733
{
17281734
kref_get(&opp->kref);
17291735
}
1736+
EXPORT_SYMBOL_GPL(dev_pm_opp_get);
17301737

17311738
void dev_pm_opp_put(struct dev_pm_opp *opp)
17321739
{

drivers/opp/opp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ struct opp_table {
250250
};
251251

252252
/* Routines internal to opp core */
253-
void dev_pm_opp_get(struct dev_pm_opp *opp);
254253
bool _opp_remove_all_static(struct opp_table *opp_table);
255254
void _get_opp_table_kref(struct opp_table *opp_table);
256255
int _get_opp_count(struct opp_table *opp_table);

include/linux/pm_opp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct dev_pm_opp_data {
100100
#if defined(CONFIG_PM_OPP)
101101

102102
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);
103104
void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
104105

105106
unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index);
@@ -160,6 +161,7 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
160161
struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
161162
unsigned int *bw, int index);
162163

164+
void dev_pm_opp_get(struct dev_pm_opp *opp);
163165
void dev_pm_opp_put(struct dev_pm_opp *opp);
164166

165167
int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
@@ -205,6 +207,8 @@ static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *
205207
return ERR_PTR(-EOPNOTSUPP);
206208
}
207209

210+
static inline void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) {}
211+
208212
static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
209213

210214
static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
@@ -341,6 +345,8 @@ static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
341345
return ERR_PTR(-EOPNOTSUPP);
342346
}
343347

348+
static inline void dev_pm_opp_get(struct dev_pm_opp *opp) {}
349+
344350
static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
345351

346352
static inline int

0 commit comments

Comments
 (0)