[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230518040729.8789-1-sen.chu@mediatek.com>
Date: Thu, 18 May 2023 12:07:29 +0800
From: Sen Chu <sen.chu@...iatek.com>
To: Stephen Boyd <sboyd@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>
CC: <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-mediatek@...ts.infradead.org>,
Sen Chu <sen.chu@...iatek.com>
Subject: [PATCH v2] spmi: mediatek: add device id check
Add device id check for spmi write API.
Signed-off-by: Sen Chu <sen.chu@...iatek.com>
---
Change in v1:
Fix: this should be unlikely(sid & ~0xf)
[Sen Chu <sen.chu@...iatek.com>]
---
---
drivers/spmi/spmi-mtk-pmif.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c
index b3c991e1ea40..78a96e00ed54 100644
--- a/drivers/spmi/spmi-mtk-pmif.c
+++ b/drivers/spmi/spmi-mtk-pmif.c
@@ -378,6 +378,12 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
int ret;
u32 data, cmd;
+ /* Check for argument validation. */
+ if (unlikely(sid & ~0xf)) {
+ dev_err(&ctrl->dev, "exceed the max slv id\n");
+ return -EINVAL;
+ }
+
if (len > 4) {
dev_err(&ctrl->dev, "pmif supports 1..4 bytes per trans, but:%zu requested", len);
--
2.18.0
Powered by blists - more mailing lists