public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: krzk@kernel.org (Krzysztof Kozlowski)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/9] pinctrl: samsung: Use generic of_device_get_match_data helper
Date: Mon, 26 Dec 2016 11:41:42 +0200	[thread overview]
Message-ID: <20161226094142.hajrgye5632mgoup@kozik-lap> (raw)
In-Reply-To: <CA+Ln22FfYkxJAOtpfr1UUai6vZej09NSZa6cz2cuO2aHN8Trmw@mail.gmail.com>

On Mon, Dec 26, 2016 at 02:44:26PM +0900, Tomasz Figa wrote:
> 2016-12-25 21:56 GMT+09:00 Krzysztof Kozlowski <krzk@kernel.org>:
> > On Fri, Dec 23, 2016 at 01:24:44PM +0100, Marek Szyprowski wrote:
> >> Replace custom code with generic helper.
> >>
> >> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> >> ---
> >>  drivers/pinctrl/samsung/pinctrl-samsung.c | 9 ++++-----
> >>  1 file changed, 4 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> >> index 4d9262051ff1..a6c2ea74e0f3 100644
> >> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> >> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> >> @@ -27,6 +27,7 @@
> >>  #include <linux/err.h>
> >>  #include <linux/gpio.h>
> >>  #include <linux/irqdomain.h>
> >> +#include <linux/of_device.h>
> >>  #include <linux/spinlock.h>
> >>  #include <linux/syscore_ops.h>
> >>
> >> @@ -967,15 +968,13 @@ static int samsung_gpiolib_unregister(struct platform_device *pdev,
> >>       return 0;
> >>  }
> >>
> >> -static const struct of_device_id samsung_pinctrl_dt_match[];
> >> -
> >>  /* retrieve the soc specific data */
> >>  static const struct samsung_pin_ctrl *
> >>  samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
> >>                            struct platform_device *pdev)
> >>  {
> >>       int id;
> >> -     const struct of_device_id *match;
> >> +     const struct samsung_pin_ctrl *match_data;
> >>       struct device_node *node = pdev->dev.of_node;
> >>       struct device_node *np;
> >>       const struct samsung_pin_bank_data *bdata;
> >> @@ -990,8 +989,8 @@ static int samsung_gpiolib_unregister(struct platform_device *pdev,
> >>               dev_err(&pdev->dev, "failed to get alias id\n");
> >>               return ERR_PTR(-ENOENT);
> >>       }
> >> -     match = of_match_node(samsung_pinctrl_dt_match, node);
> >> -     ctrl = (struct samsung_pin_ctrl *)match->data + id;
> >> +     match_data = of_device_get_match_data(&pdev->dev);
> >> +     ctrl = match_data + id;
> >
> > Either you need a check for match_data != NULL or just remove match_data
> > and:
> >         ctrl = of_device_get_match_data();
> >         ctrl += id;
> >
> > Actually match_data can be removed even with the check for non-NULL...
> 
> I don't think this function can ever return NULL if the match array
> contains a non-NULL value for each compatible string and the driver
> can be probed only by DT.

Practically it cannot (or it should not) but defensive coding is a good
practice...

> But you still need to cast the match data pointer to the correct type
> and using a variable for it IMHO makes the code cleaner.

What do you mean by casting through variable? match_data and ctrl are
the same type so there is no change by intermediate variable. It just
obfuscates the code.

BR,
Krzysztof

  reply	other threads:[~2016-12-26  9:41 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161223122513epcas1p394d93d72d2d32c8910aafd1f6cc6b5e2@epcas1p3.samsung.com>
2016-12-23 12:24 ` [PATCH 0/9] Runtime PM for Exynos pin controller driver Marek Szyprowski
2016-12-23 12:24   ` [PATCH 1/9] ARM: dts: exynos: Add PMU syscon to pinctrl nodes Marek Szyprowski
2016-12-26  5:36     ` Tomasz Figa
2016-12-23 12:24   ` [PATCH 2/9] ARM: dts: exynos: Add pinctrl sleep state for 542x i2s module Marek Szyprowski
2016-12-26  5:39     ` Tomasz Figa
2016-12-23 12:24   ` [PATCH 3/9] pinctrl: samsung: Remove dead code Marek Szyprowski
2016-12-25 12:51     ` Krzysztof Kozlowski
2016-12-26  5:40     ` Tomasz Figa
2016-12-23 12:24   ` [PATCH 4/9] pinctrl: samsung: Use generic of_device_get_match_data helper Marek Szyprowski
2016-12-25 12:56     ` Krzysztof Kozlowski
2016-12-26  5:44       ` Tomasz Figa
2016-12-26  9:41         ` Krzysztof Kozlowski [this message]
2016-12-27 10:28           ` Bartlomiej Zolnierkiewicz
2016-12-23 12:24   ` [PATCH 5/9] pinctrl: samsung: Move retention control from mach-exynos to the pinctrl driver Marek Szyprowski
2016-12-25 13:42     ` Krzysztof Kozlowski
2016-12-27 10:15       ` Marek Szyprowski
2016-12-26  5:55     ` Tomasz Figa
2016-12-27 10:12       ` Marek Szyprowski
2016-12-27 15:39         ` Krzysztof Kozlowski
2016-12-30  9:19     ` Linus Walleij
2016-12-23 12:24   ` [PATCH 6/9] pinctrl: samsung: Replace syscore ops with standard platform device pm_ops Marek Szyprowski
2016-12-25 18:47     ` Krzysztof Kozlowski
2016-12-26  5:57     ` Tomasz Figa
2016-12-27 10:17       ` Marek Szyprowski
2016-12-23 12:24   ` [PATCH 7/9] pinctrl: samsung: Add property to mark pad state as suitable for power down Marek Szyprowski
2016-12-25 19:19     ` Krzysztof Kozlowski
2016-12-26  6:02       ` Tomasz Figa
2016-12-27 10:30       ` Marek Szyprowski
2016-12-27 15:33         ` Krzysztof Kozlowski
2016-12-30  9:23           ` Linus Walleij
2016-12-30 11:55           ` Marek Szyprowski
2016-12-30 15:05             ` Krzysztof Kozlowski
2016-12-23 12:24   ` [PATCH 8/9] pinctrl: samsung: Add runtime PM support Marek Szyprowski
2016-12-25 19:26     ` Krzysztof Kozlowski
2016-12-26  6:11     ` Tomasz Figa
2016-12-23 12:24   ` [PATCH 9/9] ARM: dts: exynos: Add audio power domain support to Exynos542x SoCs Marek Szyprowski
2016-12-24 10:10   ` [PATCH 0/9] Runtime PM for Exynos pin controller driver Anand Moon
2016-12-27  8:29     ` Marek Szyprowski

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=20161226094142.hajrgye5632mgoup@kozik-lap \
    --to=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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