linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Jianqun Xu <jay.xu@rock-chips.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@xilinx.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org
Cc: Bamvor Jian Zhang <bamv2005@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Gregory Clement <gregory.clement@bootlin.com>,
	Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	Heiko Stuebner <heiko@sntech.de>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Andy Shevchenko <andy@kernel.org>
Subject: [PATCH v1 14/19] pinctrl: st: Use temporary variable for struct device
Date: Fri,  5 Nov 2021 14:42:37 +0200	[thread overview]
Message-ID: <20211105124242.27288-14-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com>

Use temporary variable for struct device to make code neater.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/pinctrl-st.c | 73 +++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 39 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index ae8783b34ed2..f592e9ad93fc 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -814,26 +814,25 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 {
 	struct st_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
 	const struct st_pctl_group *grp;
+	struct device *dev = info->dev;
 	struct pinctrl_map *new_map;
 	struct device_node *parent;
 	int map_num, i;
 
 	grp = st_pctl_find_group_by_name(info, np->name);
 	if (!grp) {
-		dev_err(info->dev, "unable to find group for node %pOFn\n",
-			np);
+		dev_err(dev, "unable to find group for node %pOFn\n", np);
 		return -EINVAL;
 	}
 
 	map_num = grp->npins + 1;
-	new_map = devm_kcalloc(pctldev->dev,
-				map_num, sizeof(*new_map), GFP_KERNEL);
+	new_map = devm_kcalloc(dev, map_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
 
 	parent = of_get_parent(np);
 	if (!parent) {
-		devm_kfree(pctldev->dev, new_map);
+		devm_kfree(dev, new_map);
 		return -EINVAL;
 	}
 
@@ -853,7 +852,7 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 		new_map[i].data.configs.configs = &grp->pin_conf[i].config;
 		new_map[i].data.configs.num_configs = 1;
 	}
-	dev_info(pctldev->dev, "maps: function %s group %s num %d\n",
+	dev_info(dev, "maps: function %s group %s num %d\n",
 		(*map)->data.mux.function, grp->name, map_num);
 
 	return 0;
@@ -1173,6 +1172,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
 	/* bank pad direction val altfunction */
 	const __be32 *list;
 	struct property *pp;
+	struct device *dev = info->dev;
 	struct st_pinconf *conf;
 	struct device_node *pins;
 	int i = 0, npins = 0, nr_props, ret = 0;
@@ -1197,9 +1197,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
 
 	grp->npins = npins;
 	grp->name = np->name;
-	grp->pins = devm_kcalloc(info->dev, npins, sizeof(u32), GFP_KERNEL);
-	grp->pin_conf = devm_kcalloc(info->dev,
-					npins, sizeof(*conf), GFP_KERNEL);
+	grp->pins = devm_kcalloc(dev, npins, sizeof(*grp->pins), GFP_KERNEL);
+	grp->pin_conf = devm_kcalloc(dev, npins, sizeof(*grp->pin_conf), GFP_KERNEL);
 
 	if (!grp->pins || !grp->pin_conf) {
 		ret = -ENOMEM;
@@ -1247,6 +1246,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
 static int st_pctl_parse_functions(struct device_node *np,
 			struct st_pinctrl *info, u32 index, int *grp_index)
 {
+	struct device *dev = info->dev;
 	struct device_node *child;
 	struct st_pmx_func *func;
 	struct st_pctl_group *grp;
@@ -1256,11 +1256,10 @@ static int st_pctl_parse_functions(struct device_node *np,
 	func->name = np->name;
 	func->ngroups = of_get_child_count(np);
 	if (func->ngroups == 0) {
-		dev_err(info->dev, "No groups defined\n");
+		dev_err(dev, "No groups defined\n");
 		return -EINVAL;
 	}
-	func->groups = devm_kcalloc(info->dev,
-			func->ngroups, sizeof(char *), GFP_KERNEL);
+	func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL);
 	if (!func->groups)
 		return -ENOMEM;
 
@@ -1275,8 +1274,7 @@ static int st_pctl_parse_functions(struct device_node *np,
 			return ret;
 		}
 	}
-	dev_info(info->dev, "Function[%d\t name:%s,\tgroups:%d]\n",
-				index, func->name, func->ngroups);
+	dev_info(dev, "Function[%d\t name:%s,\tgroups:%d]\n", index, func->name, func->ngroups);
 
 	return 0;
 }
@@ -1577,10 +1575,11 @@ static const struct of_device_id st_pctl_of_match[] = {
 static int st_pctl_probe_dt(struct platform_device *pdev,
 	struct pinctrl_desc *pctl_desc, struct st_pinctrl *info)
 {
+	struct device *dev = &pdev->dev;
 	int ret = 0;
 	int i = 0, j = 0, k = 0, bank;
 	struct pinctrl_pin_desc *pdesc;
-	struct device_node *np = pdev->dev.of_node;
+	struct device_node *np = dev->of_node;
 	struct device_node *child;
 	int grp_index = 0;
 	int irq = 0;
@@ -1588,30 +1587,26 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
 
 	st_pctl_dt_child_count(info, np);
 	if (!info->nbanks) {
-		dev_err(&pdev->dev, "you need at least one gpio bank\n");
+		dev_err(dev, "you need at least one gpio bank\n");
 		return -EINVAL;
 	}
 
-	dev_info(&pdev->dev, "nbanks = %d\n", info->nbanks);
-	dev_info(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
-	dev_info(&pdev->dev, "ngroups = %d\n", info->ngroups);
+	dev_info(dev, "nbanks = %d\n", info->nbanks);
+	dev_info(dev, "nfunctions = %d\n", info->nfunctions);
+	dev_info(dev, "ngroups = %d\n", info->ngroups);
 
-	info->functions = devm_kcalloc(&pdev->dev,
-		info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
+	info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
 
-	info->groups = devm_kcalloc(&pdev->dev,
-			info->ngroups, sizeof(*info->groups),
-			GFP_KERNEL);
+	info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL);
 
-	info->banks = devm_kcalloc(&pdev->dev,
-			info->nbanks, sizeof(*info->banks), GFP_KERNEL);
+	info->banks = devm_kcalloc(dev, info->nbanks, sizeof(*info->banks), GFP_KERNEL);
 
 	if (!info->functions || !info->groups || !info->banks)
 		return -ENOMEM;
 
 	info->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
 	if (IS_ERR(info->regmap)) {
-		dev_err(info->dev, "No syscfg phandle specified\n");
+		dev_err(dev, "No syscfg phandle specified\n");
 		return PTR_ERR(info->regmap);
 	}
 	info->data = of_match_node(st_pctl_of_match, np)->data;
@@ -1621,7 +1616,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
 	if (irq > 0) {
 		res = platform_get_resource_byname(pdev,
 					IORESOURCE_MEM, "irqmux");
-		info->irqmux_base = devm_ioremap_resource(&pdev->dev, res);
+		info->irqmux_base = devm_ioremap_resource(dev, res);
 
 		if (IS_ERR(info->irqmux_base))
 			return PTR_ERR(info->irqmux_base);
@@ -1632,8 +1627,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
 	}
 
 	pctl_desc->npins = info->nbanks * ST_GPIO_PINS_PER_BANK;
-	pdesc =	devm_kcalloc(&pdev->dev,
-			pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL);
+	pdesc =	devm_kcalloc(dev, pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL);
 	if (!pdesc)
 		return -ENOMEM;
 
@@ -1663,7 +1657,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
 			ret = st_pctl_parse_functions(child, info,
 							i++, &grp_index);
 			if (ret) {
-				dev_err(&pdev->dev, "No functions found.\n");
+				dev_err(dev, "No functions found.\n");
 				of_node_put(child);
 				return ret;
 			}
@@ -1675,24 +1669,25 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
 
 static int st_pctl_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct st_pinctrl *info;
 	struct pinctrl_desc *pctl_desc;
 	int ret, i;
 
-	if (!pdev->dev.of_node) {
-		dev_err(&pdev->dev, "device node not found.\n");
+	if (!dev->of_node) {
+		dev_err(dev, "device node not found.\n");
 		return -EINVAL;
 	}
 
-	pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL);
+	pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL);
 	if (!pctl_desc)
 		return -ENOMEM;
 
-	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+	info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
-	info->dev = &pdev->dev;
+	info->dev = dev;
 	platform_set_drvdata(pdev, info);
 	ret = st_pctl_probe_dt(pdev, pctl_desc, info);
 	if (ret)
@@ -1702,11 +1697,11 @@ static int st_pctl_probe(struct platform_device *pdev)
 	pctl_desc->pctlops	= &st_pctlops;
 	pctl_desc->pmxops	= &st_pmxops;
 	pctl_desc->confops	= &st_confops;
-	pctl_desc->name		= dev_name(&pdev->dev);
+	pctl_desc->name		= dev_name(dev);
 
-	info->pctl = devm_pinctrl_register(&pdev->dev, pctl_desc, info);
+	info->pctl = devm_pinctrl_register(dev, pctl_desc, info);
 	if (IS_ERR(info->pctl)) {
-		dev_err(&pdev->dev, "Failed pinctrl registration\n");
+		dev_err(dev, "Failed pinctrl registration\n");
 		return PTR_ERR(info->pctl);
 	}
 
-- 
2.33.0


  parent reply	other threads:[~2021-11-05 12:43 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 12:42 [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() Andy Shevchenko
2021-11-05 12:42 ` [PATCH v1 02/19] lib/string_helpers: Introduce managed variant of kasprintf_strarray() Andy Shevchenko
2021-11-05 12:42 ` [PATCH v1 03/19] pinctrl/rockchip: Drop wrong kernel doc annotation Andy Shevchenko
2021-11-06 16:32   ` Heiko Stübner
2021-11-05 12:42 ` [PATCH v1 04/19] pinctrl/rockchip: Use temporary variable for struct device Andy Shevchenko
2021-11-08 12:46   ` Heiko Stübner
2021-11-05 12:42 ` [PATCH v1 05/19] pinctrl/rockchip: Make use of the devm_platform_get_and_ioremap_resource() Andy Shevchenko
2021-11-08 12:48   ` Heiko Stübner
2021-11-05 12:42 ` [PATCH v1 06/19] pinctrl/rockchip: Convert to use dev_err_probe() Andy Shevchenko
2021-11-08 12:49   ` Heiko Stübner
2021-11-05 12:42 ` [PATCH v1 07/19] pinctrl/rockchip: Switch to use devm_kasprintf_strarray() Andy Shevchenko
2021-11-08 12:51   ` Heiko Stübner
2021-11-05 12:42 ` [PATCH v1 08/19] pinctrl: armada-37xx: Fix function name in the kernel doc Andy Shevchenko
2021-11-08 10:37   ` Gregory CLEMENT
2021-11-05 12:42 ` [PATCH v1 09/19] pinctrl: armada-37xx: Use temporary variable for struct device Andy Shevchenko
2021-11-08 10:49   ` Gregory CLEMENT
2021-11-05 12:42 ` [PATCH v1 10/19] pinctrl: armada-37xx: Make use of the devm_platform_ioremap_resource() Andy Shevchenko
2021-11-08 10:56   ` Gregory CLEMENT
2021-11-05 12:42 ` [PATCH v1 11/19] pinctrl: armada-37xx: Convert to use dev_err_probe() Andy Shevchenko
2021-11-08 10:59   ` Gregory CLEMENT
2021-11-05 12:42 ` [PATCH v1 12/19] pinctrl: armada-37xx: Switch to use devm_kasprintf_strarray() Andy Shevchenko
2021-11-08 11:09   ` Gregory CLEMENT
2021-11-05 12:42 ` [PATCH v1 13/19] pinctrl: st: Drop wrong kernel doc annotations Andy Shevchenko
2021-11-09 11:32   ` Linus Walleij
2021-11-09 12:04     ` Andy Shevchenko
2021-11-05 12:42 ` Andy Shevchenko [this message]
2021-11-06  7:50   ` [PATCH v1 14/19] pinctrl: st: Use temporary variable for struct device Joe Perches
     [not found]     ` <CAHp75Ve0Bv9VsWFFZxL9wYk=Z_Mm7nat-vf7g8HHTiROi7EY=Q@mail.gmail.com>
2021-11-06  8:28       ` Joe Perches
2021-11-08  9:26         ` Andy Shevchenko
2021-11-09 11:55           ` Linus Walleij
2021-11-09 12:07             ` Andy Shevchenko
2021-11-09 12:09             ` Andy Shevchenko
2021-11-05 12:42 ` [PATCH v1 15/19] pinctrl: st: Make use of the devm_platform_ioremap_resource_byname() Andy Shevchenko
2021-11-09 11:33   ` Linus Walleij
2021-11-05 12:42 ` [PATCH v1 16/19] pinctrl: st: Convert to use dev_err_probe() Andy Shevchenko
2021-11-09 11:34   ` Linus Walleij
2021-11-05 12:42 ` [PATCH v1 17/19] pinctrl: st: Switch to use devm_kasprintf_strarray() Andy Shevchenko
2021-11-09 11:34   ` Linus Walleij
2021-11-05 12:42 ` [PATCH v1 18/19] pinctrl: zynqmp: Unify pin naming Andy Shevchenko
2021-11-09 11:34   ` Linus Walleij
2021-11-05 12:42 ` [PATCH v1 19/19] gpio: mockup: Switch to use kasprintf_strarray() Andy Shevchenko
2021-11-09 11:35   ` Linus Walleij
2021-11-16  9:12   ` Bartosz Golaszewski
2021-11-06  7:34 ` [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() Joe Perches
2021-11-09 11:42 ` Linus Walleij
2021-11-15 11:23   ` Andy Shevchenko
2021-11-18 16:56     ` Andy Shevchenko
2021-11-18 20:30       ` Bartosz Golaszewski

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=20211105124242.27288-14-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew@lunn.ch \
    --cc=andy@kernel.org \
    --cc=bamv2005@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=gregory.clement@bootlin.com \
    --cc=heiko@sntech.de \
    --cc=jay.xu@rock-chips.com \
    --cc=lakshmi.sai.krishna.potthuri@xilinx.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=michal.simek@xilinx.com \
    --cc=patrice.chotard@foss.st.com \
    --cc=sebastian.hesselbarth@gmail.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).