From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjorn Andersson Subject: Re: [PATCH 1/2] soc: qcom: smsm: Handle probe deferral Date: Mon, 27 Mar 2017 23:18:29 -0700 Message-ID: <20170328061829.GI70446@Bjorns-MacBook-Pro-2.local> References: <20170315114357.14446-1-j.neuschaefer@gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Return-path: Received: from mail-pg0-f50.google.com ([74.125.83.50]:33401 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752766AbdC1GSd (ORCPT ); Tue, 28 Mar 2017 02:18:33 -0400 Received: by mail-pg0-f50.google.com with SMTP id n5so55189985pgh.0 for ; Mon, 27 Mar 2017 23:18:32 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20170315114357.14446-1-j.neuschaefer@gmx.net> Sender: linux-arm-msm-owner@vger.kernel.org List-Id: linux-arm-msm@vger.kernel.org To: Jonathan Neusch?fer Cc: linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Andy Gross , David Brown , linux-kernel@vger.kernel.org On Wed 15 Mar 04:43 PDT 2017, Jonathan Neusch?fer wrote: > If qcom_smem_get or qcom_smem_alloc return -EPROBE_DEFER, let the caller > the caller handle it, instead of treating it as an error. > > Signed-off-by: Jonathan Neuschäfer > > --- > v1: > - TODO: Reading qcom_smsm_probe, I noticed memory leaks in error paths: > smsm, smsm->entries, etc. are allocated (with devm_kzalloc), but not > freed when the function returns early. This should be addressed at > some point (in a separate patch). > --- > drivers/soc/qcom/smsm.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/soc/qcom/smsm.c b/drivers/soc/qcom/smsm.c > index d0337b2a71c8..3918645e5708 100644 > --- a/drivers/soc/qcom/smsm.c > +++ b/drivers/soc/qcom/smsm.c > @@ -439,7 +439,9 @@ static int smsm_get_size_info(struct qcom_smsm *smsm) > } *info; > > info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SIZE_INFO, &size); > - if (PTR_ERR(info) == -ENOENT || size != sizeof(*info)) { > + if (PTR_ERR(info) == -EPROBE_DEFER) { > + return PTR_ERR(info); > + } else if (PTR_ERR(info) == -ENOENT || size != sizeof(*info)) { The following elseif was supposed to take care of this case, but I clearly screwed this up. Rather than adding a special case for EPROBE_DEFER before the two checks and then fix up the original expression to make errors fall back to the original else, I think you should rearrange the conditionals. Probably better to write it like this instead: if (IS_ERR(info) && PTR_ERR(info) != -ENOENT) { if (PTR_ERR(info) != -EPROBE_DEFER) dev_err(smsm->dev, "unable to retrieve smsm size info\n"); return PTR_ERR(info); } else if (IS_ERR(info) || size != sizeof(*info)) { dev_warn(smsm->dev, "no smsm size info, using defaults\n"); smsm->num_entries = SMSM_DEFAULT_NUM_ENTRIES; smsm->num_hosts = SMSM_DEFAULT_NUM_HOSTS; return 0; } > dev_warn(smsm->dev, "no smsm size info, using defaults\n"); > smsm->num_entries = SMSM_DEFAULT_NUM_ENTRIES; > smsm->num_hosts = SMSM_DEFAULT_NUM_HOSTS; > @@ -515,7 +517,9 @@ static int qcom_smsm_probe(struct platform_device *pdev) > /* Acquire the main SMSM state vector */ > ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE, > smsm->num_entries * sizeof(u32)); > - if (ret < 0 && ret != -EEXIST) { > + if (ret == -EPROBE_DEFER) { > + return ret; > + } else if (ret < 0 && ret != -EEXIST) { The idiomatic way to write this is: if (ret < 0 && ret != -EEXIST) { if (ret != -EPROBE_DEFER) dev_err(); return ret; } However, for us to reach this point in smsm_probe() the above qcom_smem_get() must have returned successfully, i.e. we have SMEM in place so there's no need to handle this case specifically. > dev_err(&pdev->dev, "unable to allocate shared state entry\n"); > return ret; > } Regards, Bjorn