Skip to content

Commit

Permalink
interconnect: Add devm_of_icc_get() as exported API for users
Browse files Browse the repository at this point in the history
Users can use devm version of of_icc_get() to benefit from automatic
resource release.

Signed-off-by: Akash Asthana <akashast@codeaurora.org>
Reviewed by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/1586946198-13912-2-git-send-email-akashast@codeaurora.org
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
  • Loading branch information
Akash Asthana authored and Georgi Djakov committed Apr 27, 2020
1 parent 6a8b55e commit e145d9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drivers/interconnect/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,31 @@ static struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec)
return node;
}

static void devm_icc_release(struct device *dev, void *res)
{
icc_put(*(struct icc_path **)res);
}

struct icc_path *devm_of_icc_get(struct device *dev, const char *name)
{
struct icc_path **ptr, *path;

ptr = devres_alloc(devm_icc_release, sizeof(**ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

path = of_icc_get(dev, name);
if (!IS_ERR(path)) {
*ptr = path;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}

return path;
}
EXPORT_SYMBOL_GPL(devm_of_icc_get);

/**
* of_icc_get() - get a path handle from a DT node based on name
* @dev: device pointer for the consumer device
Expand Down
7 changes: 7 additions & 0 deletions include/linux/interconnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct device;
struct icc_path *icc_get(struct device *dev, const int src_id,
const int dst_id);
struct icc_path *of_icc_get(struct device *dev, const char *name);
struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
void icc_put(struct icc_path *path);
int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
void icc_set_tag(struct icc_path *path, u32 tag);
Expand All @@ -46,6 +47,12 @@ static inline struct icc_path *of_icc_get(struct device *dev,
return NULL;
}

static inline struct icc_path *devm_of_icc_get(struct device *dev,
const char *name)
{
return NULL;
}

static inline void icc_put(struct icc_path *path)
{
}
Expand Down

0 comments on commit e145d9a

Please sign in to comment.