* [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get()
@ 2021-06-18 11:15 Stephan Gerhold
2021-06-18 11:15 ` [PATCH 2/3] remoteproc: qcom_q6v5: Use devm_qcom_smem_state_get() to fix missing put() Stephan Gerhold
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stephan Gerhold @ 2021-06-18 11:15 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Andy Gross, Ohad Ben-Cohen, Mathieu Poirier, linux-arm-msm,
linux-remoteproc, ~postmarketos/upstreaming, Stephan Gerhold
It is easy to forget to call qcom_smem_state_put() after
a qcom_smem_state_get(). Introduce a devm_qcom_smem_state_get()
helper function that automates this so that qcom_smem_state_put()
is automatically called when a device is removed.
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
I use this in my WIP bam-dmux driver, so it might simplify coordination
later if we can somehow get this in for 5.14 (if it isn't too late yet).
Similar code can be found in clk-devres.c for example:
https://elixir.bootlin.com/linux/v5.13-rc6/source/drivers/clk/clk-devres.c#L7
---
drivers/soc/qcom/smem_state.c | 36 +++++++++++++++++++++++++++++
include/linux/soc/qcom/smem_state.h | 7 ++++++
2 files changed, 43 insertions(+)
diff --git a/drivers/soc/qcom/smem_state.c b/drivers/soc/qcom/smem_state.c
index d2b558438deb..31faf4aa868e 100644
--- a/drivers/soc/qcom/smem_state.c
+++ b/drivers/soc/qcom/smem_state.c
@@ -151,6 +151,42 @@ void qcom_smem_state_put(struct qcom_smem_state *state)
}
EXPORT_SYMBOL_GPL(qcom_smem_state_put);
+static void devm_qcom_smem_state_release(struct device *dev, void *res)
+{
+ qcom_smem_state_put(*(struct qcom_smem_state **)res);
+}
+
+/**
+ * devm_qcom_smem_state_get() - acquire handle to a devres managed state
+ * @dev: client device pointer
+ * @con_id: name of the state to lookup
+ * @bit: flags from the state reference, indicating which bit's affected
+ *
+ * Returns handle to the state, or ERR_PTR(). qcom_smem_state_put() is called
+ * automatically when @dev is removed.
+ */
+struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev,
+ const char *con_id,
+ unsigned *bit)
+{
+ struct qcom_smem_state **ptr, *state;
+
+ ptr = devres_alloc(devm_qcom_smem_state_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ state = qcom_smem_state_get(dev, con_id, bit);
+ if (!IS_ERR(state)) {
+ *ptr = state;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return state;
+}
+EXPORT_SYMBOL_GPL(devm_qcom_smem_state_get);
+
/**
* qcom_smem_state_register() - register a new state
* @of_node: of_node used for matching client lookups
diff --git a/include/linux/soc/qcom/smem_state.h b/include/linux/soc/qcom/smem_state.h
index 63ad8cddad14..17c56a50302f 100644
--- a/include/linux/soc/qcom/smem_state.h
+++ b/include/linux/soc/qcom/smem_state.h
@@ -14,6 +14,7 @@ struct qcom_smem_state_ops {
#ifdef CONFIG_QCOM_SMEM_STATE
struct qcom_smem_state *qcom_smem_state_get(struct device *dev, const char *con_id, unsigned *bit);
+struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev, const char *con_id, unsigned *bit);
void qcom_smem_state_put(struct qcom_smem_state *);
int qcom_smem_state_update_bits(struct qcom_smem_state *state, u32 mask, u32 value);
@@ -29,6 +30,12 @@ static inline struct qcom_smem_state *qcom_smem_state_get(struct device *dev,
return ERR_PTR(-EINVAL);
}
+static inline struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev,
+ const char *con_id, unsigned *bit)
+{
+ return ERR_PTR(-EINVAL);
+}
+
static inline void qcom_smem_state_put(struct qcom_smem_state *state)
{
}
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] remoteproc: qcom_q6v5: Use devm_qcom_smem_state_get() to fix missing put()
2021-06-18 11:15 [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Stephan Gerhold
@ 2021-06-18 11:15 ` Stephan Gerhold
2021-06-18 11:15 ` [PATCH 3/3] remoteproc: qcom_wcnss: Use devm_qcom_smem_state_get() Stephan Gerhold
2021-06-23 18:30 ` [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Bjorn Andersson
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Gerhold @ 2021-06-18 11:15 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Andy Gross, Ohad Ben-Cohen, Mathieu Poirier, linux-arm-msm,
linux-remoteproc, ~postmarketos/upstreaming, Stephan Gerhold
qcom_q6v5 is requesting a smem state with qcom_smem_state_get() but
qcom_smem_state_put() is not called anywhere. Use the new devm_()
variant to fix this without making the code more complicated.
Fixes: 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
drivers/remoteproc/qcom_q6v5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/remoteproc/qcom_q6v5.c b/drivers/remoteproc/qcom_q6v5.c
index 9627a950928e..7e9244c748da 100644
--- a/drivers/remoteproc/qcom_q6v5.c
+++ b/drivers/remoteproc/qcom_q6v5.c
@@ -280,7 +280,7 @@ int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev,
return ret;
}
- q6v5->state = qcom_smem_state_get(&pdev->dev, "stop", &q6v5->stop_bit);
+ q6v5->state = devm_qcom_smem_state_get(&pdev->dev, "stop", &q6v5->stop_bit);
if (IS_ERR(q6v5->state)) {
dev_err(&pdev->dev, "failed to acquire stop state\n");
return PTR_ERR(q6v5->state);
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] remoteproc: qcom_wcnss: Use devm_qcom_smem_state_get()
2021-06-18 11:15 [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Stephan Gerhold
2021-06-18 11:15 ` [PATCH 2/3] remoteproc: qcom_q6v5: Use devm_qcom_smem_state_get() to fix missing put() Stephan Gerhold
@ 2021-06-18 11:15 ` Stephan Gerhold
2021-06-23 18:30 ` [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Bjorn Andersson
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Gerhold @ 2021-06-18 11:15 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Andy Gross, Ohad Ben-Cohen, Mathieu Poirier, linux-arm-msm,
linux-remoteproc, ~postmarketos/upstreaming, Stephan Gerhold
Use the new managed devm_qcom_smem_state_get() variant instead of
calling qcom_smem_state_put() explicitly in remove() to simplify the
code a bit.
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
drivers/remoteproc/qcom_wcnss.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c
index 5f3455aa7e0e..f1cbc6b2edbb 100644
--- a/drivers/remoteproc/qcom_wcnss.c
+++ b/drivers/remoteproc/qcom_wcnss.c
@@ -624,8 +624,8 @@ static int wcnss_probe(struct platform_device *pdev)
wcnss->stop_ack_irq = ret;
if (wcnss->stop_ack_irq) {
- wcnss->state = qcom_smem_state_get(&pdev->dev, "stop",
- &wcnss->stop_bit);
+ wcnss->state = devm_qcom_smem_state_get(&pdev->dev, "stop",
+ &wcnss->stop_bit);
if (IS_ERR(wcnss->state)) {
ret = PTR_ERR(wcnss->state);
goto detach_pds;
@@ -659,7 +659,6 @@ static int wcnss_remove(struct platform_device *pdev)
of_platform_depopulate(&pdev->dev);
- qcom_smem_state_put(wcnss->state);
rproc_del(wcnss->rproc);
qcom_remove_sysmon_subdev(wcnss->sysmon);
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get()
2021-06-18 11:15 [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Stephan Gerhold
2021-06-18 11:15 ` [PATCH 2/3] remoteproc: qcom_q6v5: Use devm_qcom_smem_state_get() to fix missing put() Stephan Gerhold
2021-06-18 11:15 ` [PATCH 3/3] remoteproc: qcom_wcnss: Use devm_qcom_smem_state_get() Stephan Gerhold
@ 2021-06-23 18:30 ` Bjorn Andersson
2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2021-06-23 18:30 UTC (permalink / raw)
To: Stephan Gerhold
Cc: Andy Gross, Ohad Ben-Cohen, Mathieu Poirier, linux-arm-msm,
linux-remoteproc, ~postmarketos/upstreaming
On Fri 18 Jun 06:15 CDT 2021, Stephan Gerhold wrote:
> It is easy to forget to call qcom_smem_state_put() after
> a qcom_smem_state_get(). Introduce a devm_qcom_smem_state_get()
> helper function that automates this so that qcom_smem_state_put()
> is automatically called when a device is removed.
>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Regards,
Bjorn
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> ---
> I use this in my WIP bam-dmux driver, so it might simplify coordination
> later if we can somehow get this in for 5.14 (if it isn't too late yet).
>
> Similar code can be found in clk-devres.c for example:
> https://elixir.bootlin.com/linux/v5.13-rc6/source/drivers/clk/clk-devres.c#L7
> ---
> drivers/soc/qcom/smem_state.c | 36 +++++++++++++++++++++++++++++
> include/linux/soc/qcom/smem_state.h | 7 ++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/drivers/soc/qcom/smem_state.c b/drivers/soc/qcom/smem_state.c
> index d2b558438deb..31faf4aa868e 100644
> --- a/drivers/soc/qcom/smem_state.c
> +++ b/drivers/soc/qcom/smem_state.c
> @@ -151,6 +151,42 @@ void qcom_smem_state_put(struct qcom_smem_state *state)
> }
> EXPORT_SYMBOL_GPL(qcom_smem_state_put);
>
> +static void devm_qcom_smem_state_release(struct device *dev, void *res)
> +{
> + qcom_smem_state_put(*(struct qcom_smem_state **)res);
> +}
> +
> +/**
> + * devm_qcom_smem_state_get() - acquire handle to a devres managed state
> + * @dev: client device pointer
> + * @con_id: name of the state to lookup
> + * @bit: flags from the state reference, indicating which bit's affected
> + *
> + * Returns handle to the state, or ERR_PTR(). qcom_smem_state_put() is called
> + * automatically when @dev is removed.
> + */
> +struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev,
> + const char *con_id,
> + unsigned *bit)
> +{
> + struct qcom_smem_state **ptr, *state;
> +
> + ptr = devres_alloc(devm_qcom_smem_state_release, sizeof(*ptr), GFP_KERNEL);
> + if (!ptr)
> + return ERR_PTR(-ENOMEM);
> +
> + state = qcom_smem_state_get(dev, con_id, bit);
> + if (!IS_ERR(state)) {
> + *ptr = state;
> + devres_add(dev, ptr);
> + } else {
> + devres_free(ptr);
> + }
> +
> + return state;
> +}
> +EXPORT_SYMBOL_GPL(devm_qcom_smem_state_get);
> +
> /**
> * qcom_smem_state_register() - register a new state
> * @of_node: of_node used for matching client lookups
> diff --git a/include/linux/soc/qcom/smem_state.h b/include/linux/soc/qcom/smem_state.h
> index 63ad8cddad14..17c56a50302f 100644
> --- a/include/linux/soc/qcom/smem_state.h
> +++ b/include/linux/soc/qcom/smem_state.h
> @@ -14,6 +14,7 @@ struct qcom_smem_state_ops {
> #ifdef CONFIG_QCOM_SMEM_STATE
>
> struct qcom_smem_state *qcom_smem_state_get(struct device *dev, const char *con_id, unsigned *bit);
> +struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev, const char *con_id, unsigned *bit);
> void qcom_smem_state_put(struct qcom_smem_state *);
>
> int qcom_smem_state_update_bits(struct qcom_smem_state *state, u32 mask, u32 value);
> @@ -29,6 +30,12 @@ static inline struct qcom_smem_state *qcom_smem_state_get(struct device *dev,
> return ERR_PTR(-EINVAL);
> }
>
> +static inline struct qcom_smem_state *devm_qcom_smem_state_get(struct device *dev,
> + const char *con_id, unsigned *bit)
> +{
> + return ERR_PTR(-EINVAL);
> +}
> +
> static inline void qcom_smem_state_put(struct qcom_smem_state *state)
> {
> }
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-23 18:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 11:15 [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Stephan Gerhold
2021-06-18 11:15 ` [PATCH 2/3] remoteproc: qcom_q6v5: Use devm_qcom_smem_state_get() to fix missing put() Stephan Gerhold
2021-06-18 11:15 ` [PATCH 3/3] remoteproc: qcom_wcnss: Use devm_qcom_smem_state_get() Stephan Gerhold
2021-06-23 18:30 ` [PATCH 1/3] soc: qcom: smem_state: Add devm_qcom_smem_state_get() Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).