From: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
York Sun <yorksun-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Subject: [PATCH] i2c: mux: reg: simplify register size checking
Date: Thu, 20 Aug 2015 23:40:46 +0200 [thread overview]
Message-ID: <1440106846-4484-1-git-send-email-wsa@the-dreams.de> (raw)
Checking was done at three different locations, just do it once and
properly at probing time.
Signed-off-by: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: York Sun <yorksun-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
York Sun: Can you test this patch? I can only build test.
drivers/i2c/muxes/i2c-mux-reg.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index 86d41d36a78340..da8926d816c8cc 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -59,9 +59,6 @@ static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id)
if (!mux->data.write_only)
ioread8(mux->data.reg);
break;
- default:
- pr_err("Invalid register size\n");
- return -EINVAL;
}
return 0;
@@ -154,10 +151,6 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
/* map address from "reg" if exists */
if (of_address_to_resource(np, 0, &res)) {
mux->data.reg_size = resource_size(&res);
- if (mux->data.reg_size > 4) {
- dev_err(&pdev->dev, "Invalid address size\n");
- return -EINVAL;
- }
mux->data.reg = devm_ioremap_resource(&pdev->dev, &res);
if (IS_ERR(mux->data.reg))
return PTR_ERR(mux->data.reg);
@@ -210,15 +203,17 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
"Register not set, using platform resource\n");
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mux->data.reg_size = resource_size(res);
- if (mux->data.reg_size > 4) {
- dev_err(&pdev->dev, "Invalid resource size\n");
- return -EINVAL;
- }
mux->data.reg = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(mux->data.reg))
return PTR_ERR(mux->data.reg);
}
+ if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&
+ mux->data.reg_size != 1) {
+ dev_err(&pdev->dev, "Invalid register size\n");
+ return -EINVAL;
+ }
+
mux->adap = devm_kzalloc(&pdev->dev,
sizeof(*mux->adap) * mux->data.n_values,
GFP_KERNEL);
--
2.1.4
next reply other threads:[~2015-08-20 21:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-20 21:40 Wolfram Sang [this message]
[not found] ` <1440106846-4484-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-08-21 3:26 ` [PATCH] i2c: mux: reg: simplify register size checking York Sun
[not found] ` <BLUPR03MB15192BDC38DC0DE8D28395FBE650-GeMU99GfrrutHeM+ReIpiOO6mTEJWrR4XA4E9RH9d+qIuWR1G4zioA@public.gmane.org>
2015-08-21 6:46 ` Wolfram Sang
2015-08-31 20:24 ` Wolfram Sang
2015-08-31 21:08 ` York Sun
2015-08-31 22:07 ` York Sun
2015-09-03 9:56 ` Wolfram Sang
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=1440106846-4484-1-git-send-email-wsa@the-dreams.de \
--to=wsa-z923lk4zbo2bacvfa/9k2g@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=yorksun-KZfg59tc24xl57MIdRCFDg@public.gmane.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;
as well as URLs for NNTP newsgroup(s).