linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: ulf.hansson@linaro.org, avifishman70@gmail.com,
	tali.perry1@gmail.com, joel@jms.id.au, venture@google.com,
	yuenn@google.com, benjaminfair@google.com,
	skhan@linuxfoundation.org, davidgow@google.com,
	pbrobinson@gmail.com, gsomlo@gmail.com, briannorris@chromium.org,
	arnd@arndb.de, krakoczy@antmicro.com, openbmc@lists.ozlabs.org,
	linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tomer Maimon <tmaimon77@gmail.com>
Subject: Re: [PATCH v2 2/2] mmc: sdhci-npcm: Add NPCM SDHCI driver
Date: Mon, 5 Dec 2022 15:41:39 +0200	[thread overview]
Message-ID: <c200557f-c30a-62f9-287a-af804e818cf1@intel.com> (raw)
In-Reply-To: <CAHp75VctiJvvk-6AWfQSU9psHvPeKECaCWPuKL9YQ_-Vt3GBGA@mail.gmail.com>

On 5/12/22 15:25, Andy Shevchenko wrote:
> On Mon, Dec 5, 2022 at 1:20 PM Tomer Maimon <tmaimon77@gmail.com> wrote:
>> On Mon, 5 Dec 2022 at 12:54, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
>>> On Mon, Dec 5, 2022 at 10:54 AM Tomer Maimon <tmaimon77@gmail.com> wrote:
> 
> ...
> 
>>>> +#include <linux/clk.h>
>>>> +#include <linux/err.h>
>>>> +#include <linux/io.h>
>>>> +#include <linux/mmc/host.h>
>>>> +#include <linux/mmc/mmc.h>
>>>> +#include <linux/module.h>
>>>
>>> I guess platform_device.h is missing here.
>> Build and work without platform_device.h, do I need it for module use?
> 
> The rule of thumb is to include headers we are the direct user of. I
> believe you have a data type and API that are defined in that header.
> 
> ...
> 
>>>> +static int npcm_sdhci_probe(struct platform_device *pdev)
>>>> +{
>>>> +       struct sdhci_pltfm_host *pltfm_host;
>>>> +       struct sdhci_host *host;
>>>> +       u32 caps;
>>>> +       int ret;
>>>> +
>>>> +       host = sdhci_pltfm_init(pdev, &npcm_sdhci_pdata, 0);
>>>> +       if (IS_ERR(host))
>>>> +               return PTR_ERR(host);
>>>> +
>>>> +       pltfm_host = sdhci_priv(host);
>>>
>>>> +       pltfm_host->clk = devm_clk_get_optional(&pdev->dev, NULL);
>>>
>>> You can't mix devm with non-devm in this way.
>> Can you explain what you mean You can't mix devm with non-devm in this
>> way, where is the mix?
>> In version 1 used devm_clk_get, is it problematic?
> 
> devm_ is problematic in your case.
> TL;DR: you need to use clk_get_optional() and clk_put().

devm_ calls exactly those, so what is the issue?

> 
> Your ->remove() callback doesn't free resources in the reversed order
> which may or, by luck, may not be the case of all possible crashes,
> UAFs, races, etc during removal stage. All the same for error path in
> ->probe().
> 
>>>> +       if (IS_ERR(pltfm_host->clk))
>>>> +               return PTR_ERR(pltfm_host->clk);
>>>> +
>>>> +       ret = clk_prepare_enable(pltfm_host->clk);
>>>> +       if (ret)
>>>> +               return ret;
>>>> +
>>>> +       caps = sdhci_readl(host, SDHCI_CAPABILITIES);
>>>> +       if (caps & SDHCI_CAN_DO_8BIT)
>>>> +               host->mmc->caps |= MMC_CAP_8_BIT_DATA;
>>>> +
>>>> +       ret = mmc_of_parse(host->mmc);
>>>> +       if (ret)
>>>> +               goto err_sdhci_add;
>>>> +
>>>> +       ret = sdhci_add_host(host);
>>>> +       if (ret)
>>>> +               goto err_sdhci_add;
>>>
>>> Why can't you use sdhci_pltfm_register()?
>> two things are missing in sdhci_pltfm_register
>> 1. clock.
> 
> Taking into account the implementation of the corresponding
> _unregister() I would add the clock handling to the _register() one.
> Perhaps via a new member of the platform data that supplies the name
> and index of the clock and hence all clk_get_optional() / clk_put will
> be moved there.
> 
>> 2. Adding SDHCI_CAN_DO_8BIT capability according the eMMC capabilities.
> 
> All the same, why can't platform data be utilised for this?
> 
>>>> +       return 0;
>>>> +
>>>> +err_sdhci_add:
>>>> +       clk_disable_unprepare(pltfm_host->clk);
>>>> +       sdhci_pltfm_free(pdev);
>>>> +       return ret;
>>>> +}
> 


  reply	other threads:[~2022-12-05 13:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05  8:53 [PATCH v2 0/2] MMC: add NPCM SDHCI driver support Tomer Maimon
2022-12-05  8:53 ` [PATCH v2 1/2] dt-bindings: mmc: npcm,sdhci: Document NPCM SDHCI controller Tomer Maimon
2022-12-05 22:24   ` Rob Herring
2022-12-05  8:53 ` [PATCH v2 2/2] mmc: sdhci-npcm: Add NPCM SDHCI driver Tomer Maimon
2022-12-05 10:54   ` Andy Shevchenko
2022-12-05 11:20     ` Tomer Maimon
2022-12-05 13:25       ` Andy Shevchenko
2022-12-05 13:41         ` Adrian Hunter [this message]
2022-12-05 14:14           ` Andy Shevchenko
2022-12-05 14:17             ` Andy Shevchenko
2022-12-05 14:33               ` Adrian Hunter
2022-12-07 13:01                 ` Tomer Maimon
2022-12-07 13:25                   ` Andy Shevchenko
2022-12-07 13:49                     ` Adrian Hunter
2022-12-07 16:48                       ` Andy Shevchenko
2022-12-08 12:58                         ` Tomer Maimon
2022-12-07 13:47   ` Adrian Hunter
2023-03-17 14:16   ` Guenter Roeck
2023-03-17 17:36     ` Andy Shevchenko
2023-03-17 18:37       ` Guenter Roeck
2023-03-23 12:19     ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c200557f-c30a-62f9-287a-af804e818cf1@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=avifishman70@gmail.com \
    --cc=benjaminfair@google.com \
    --cc=briannorris@chromium.org \
    --cc=davidgow@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gsomlo@gmail.com \
    --cc=joel@jms.id.au \
    --cc=krakoczy@antmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=pbrobinson@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tali.perry1@gmail.com \
    --cc=tmaimon77@gmail.com \
    --cc=ulf.hansson@linaro.org \
    --cc=venture@google.com \
    --cc=yuenn@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).