linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>,
	fparent@baylibre.com, linux-input@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/7] Input: mtk-pmic-keys - check for NULL on of_match_device()
Date: Wed, 28 Apr 2021 12:52:37 -0700	[thread overview]
Message-ID: <YIm9Bb3eBjYwY53R@google.com> (raw)
In-Reply-To: <20210428164219.1115537-2-mkorpershoek@baylibre.com>

Hi Mattijs,

On Wed, Apr 28, 2021 at 06:42:13PM +0200, Mattijs Korpershoek wrote:
> mtk-pmic-keys being a child device of mt6397, it will always get probed
> when mt6397_probe() is called.
> 
> This also happens when we have no device tree node matching
> mediatek,mt6397-keys.

It sounds for me that creating a platform device instance in case where
we know need OF node, but do not have one, is wasteful. Can
mt6397-core.c and/or MFD core be adjusted to not do that.

> 
> In that case, the mfd core warns us:
> 
>   [    0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]
> 
> Check return value from call to of_match_device()
> in order to prevent a NULL pointer dereference.
> 
> In case of NULL print error message and return -ENODEV
> 
> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 62391d6c7da6..12c449eed026 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -247,6 +247,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
>  	const struct of_device_id *of_id =
>  		of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev);
>  
> +	if (!of_id)
> +		return -ENODEV;
> +

So if we make MFD/6396 core smarter we would not be needing this. I
guess there is still a possibility of someone stuffing "mtk-pmic-keys"
into "driver_override" attribute of a random platform device but I
wonder if we really need to take care of such scenarios...

>  	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
>  	if (!keys)
>  		return -ENOMEM;
> -- 
> 2.27.0
> 

Thanks.

-- 
Dmitry

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-04-28 19:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 16:42 [PATCH 0/7] Input: mtk-pmic-keys - add support for MT6358 Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 1/7] Input: mtk-pmic-keys - check for NULL on of_match_device() Mattijs Korpershoek
2021-04-28 19:52   ` Dmitry Torokhov [this message]
2021-04-29  6:48     ` Mattijs Korpershoek
2021-04-29 14:48       ` Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 2/7] mfd: mt6397: add mt6358 register definitions for power key Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 3/7] mfd: mt6397: keys: use named IRQs instead of index Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 4/7] dt-bindings: input: mtk-pmic-keys: add MT6358 binding definition Mattijs Korpershoek
2021-05-03 19:28   ` Rob Herring
2021-04-28 16:42 ` [PATCH 5/7] Input: mtk-pmic-keys - add support for MT6358 Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 6/7] mfd: mt6397: Add PMIC keys " Mattijs Korpershoek
2021-04-28 16:42 ` [PATCH 7/7] arm64: dts: mt6358: add mt6358-keys node Mattijs Korpershoek
2021-04-29 14:57 ` [PATCH 0/7] Input: mtk-pmic-keys - add support for MT6358 Mattijs Korpershoek

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=YIm9Bb3eBjYwY53R@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=fparent@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mkorpershoek@baylibre.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).