Skip to content

Commit e145d9a

Browse files
Akash AsthanaGeorgi Djakov
authored andcommitted
interconnect: Add devm_of_icc_get() as exported API for users
Users can use devm version of of_icc_get() to benefit from automatic resource release. Signed-off-by: Akash Asthana <[email protected]> Reviewed by: Matthias Kaehlcke <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Georgi Djakov <[email protected]>
1 parent 6a8b55e commit e145d9a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

drivers/interconnect/core.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,31 @@ static struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec)
350350
return node;
351351
}
352352

353+
static void devm_icc_release(struct device *dev, void *res)
354+
{
355+
icc_put(*(struct icc_path **)res);
356+
}
357+
358+
struct icc_path *devm_of_icc_get(struct device *dev, const char *name)
359+
{
360+
struct icc_path **ptr, *path;
361+
362+
ptr = devres_alloc(devm_icc_release, sizeof(**ptr), GFP_KERNEL);
363+
if (!ptr)
364+
return ERR_PTR(-ENOMEM);
365+
366+
path = of_icc_get(dev, name);
367+
if (!IS_ERR(path)) {
368+
*ptr = path;
369+
devres_add(dev, ptr);
370+
} else {
371+
devres_free(ptr);
372+
}
373+
374+
return path;
375+
}
376+
EXPORT_SYMBOL_GPL(devm_of_icc_get);
377+
353378
/**
354379
* of_icc_get() - get a path handle from a DT node based on name
355380
* @dev: device pointer for the consumer device

include/linux/interconnect.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct device;
2828
struct icc_path *icc_get(struct device *dev, const int src_id,
2929
const int dst_id);
3030
struct icc_path *of_icc_get(struct device *dev, const char *name);
31+
struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
3132
void icc_put(struct icc_path *path);
3233
int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
3334
void icc_set_tag(struct icc_path *path, u32 tag);
@@ -46,6 +47,12 @@ static inline struct icc_path *of_icc_get(struct device *dev,
4647
return NULL;
4748
}
4849

50+
static inline struct icc_path *devm_of_icc_get(struct device *dev,
51+
const char *name)
52+
{
53+
return NULL;
54+
}
55+
4956
static inline void icc_put(struct icc_path *path)
5057
{
5158
}

0 commit comments

Comments
 (0)