[PATCH v2] spmi: mediatek: add device id check
Sen Chu
sen.chu at mediatek.com
Wed May 17 21:07:29 PDT 2023
Add device id check for spmi write API.
Signed-off-by: Sen Chu <sen.chu at mediatek.com>
---
Change in v1:
Fix: this should be unlikely(sid & ~0xf)
[Sen Chu <sen.chu at mediatek.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
More information about the linux-arm-kernel
mailing list