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

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 <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>

authored by

Akash Asthana and committed by
Georgi Djakov
e145d9a1 6a8b55ed

+32
+25
drivers/interconnect/core.c
··· 350 350 return node; 351 351 } 352 352 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 + 353 378 /** 354 379 * of_icc_get() - get a path handle from a DT node based on name 355 380 * @dev: device pointer for the consumer device
+7
include/linux/interconnect.h
··· 28 28 struct icc_path *icc_get(struct device *dev, const int src_id, 29 29 const int dst_id); 30 30 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); 31 32 void icc_put(struct icc_path *path); 32 33 int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); 33 34 void icc_set_tag(struct icc_path *path, u32 tag); ··· 43 42 44 43 static inline struct icc_path *of_icc_get(struct device *dev, 45 44 const char *name) 45 + { 46 + return NULL; 47 + } 48 + 49 + static inline struct icc_path *devm_of_icc_get(struct device *dev, 50 + const char *name) 46 51 { 47 52 return NULL; 48 53 }