| From 37120b974f4f6bc2ed29413142e4d7b83e17e8b7 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Fri, 13 Jun 2025 19:06:26 -0500 |
| Subject: ipmi: Fix strcpy source and destination the same |
| |
| From: Corey Minyard <corey@minyard.net> |
| |
| [ Upstream commit 8ffcb7560b4a15faf821df95e3ab532b2b020f8c ] |
| |
| The source and destination of some strcpy operations was the same. |
| Split out the part of the operations that needed to be done for those |
| particular calls so the unnecessary copy wasn't done. |
| |
| Reported-by: kernel test robot <lkp@intel.com> |
| Closes: https://lore.kernel.org/oe-kbuild-all/202506140756.EFXXvIP4-lkp@intel.com/ |
| Signed-off-by: Corey Minyard <corey@minyard.net> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/char/ipmi/ipmi_watchdog.c | 59 ++++++++++++++++++++++--------- |
| 1 file changed, 42 insertions(+), 17 deletions(-) |
| |
| diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c |
| index 9a459257489f..ca149ca8ccd6 100644 |
| --- a/drivers/char/ipmi/ipmi_watchdog.c |
| +++ b/drivers/char/ipmi/ipmi_watchdog.c |
| @@ -1190,14 +1190,8 @@ static struct ipmi_smi_watcher smi_watcher = { |
| .smi_gone = ipmi_smi_gone |
| }; |
| |
| -static int action_op(const char *inval, char *outval) |
| +static int action_op_set_val(const char *inval) |
| { |
| - if (outval) |
| - strcpy(outval, action); |
| - |
| - if (!inval) |
| - return 0; |
| - |
| if (strcmp(inval, "reset") == 0) |
| action_val = WDOG_TIMEOUT_RESET; |
| else if (strcmp(inval, "none") == 0) |
| @@ -1208,18 +1202,26 @@ static int action_op(const char *inval, char *outval) |
| action_val = WDOG_TIMEOUT_POWER_DOWN; |
| else |
| return -EINVAL; |
| - strcpy(action, inval); |
| return 0; |
| } |
| |
| -static int preaction_op(const char *inval, char *outval) |
| +static int action_op(const char *inval, char *outval) |
| { |
| + int rv; |
| + |
| if (outval) |
| - strcpy(outval, preaction); |
| + strcpy(outval, action); |
| |
| if (!inval) |
| return 0; |
| + rv = action_op_set_val(inval); |
| + if (!rv) |
| + strcpy(action, inval); |
| + return rv; |
| +} |
| |
| +static int preaction_op_set_val(const char *inval) |
| +{ |
| if (strcmp(inval, "pre_none") == 0) |
| preaction_val = WDOG_PRETIMEOUT_NONE; |
| else if (strcmp(inval, "pre_smi") == 0) |
| @@ -1232,18 +1234,26 @@ static int preaction_op(const char *inval, char *outval) |
| preaction_val = WDOG_PRETIMEOUT_MSG_INT; |
| else |
| return -EINVAL; |
| - strcpy(preaction, inval); |
| return 0; |
| } |
| |
| -static int preop_op(const char *inval, char *outval) |
| +static int preaction_op(const char *inval, char *outval) |
| { |
| + int rv; |
| + |
| if (outval) |
| - strcpy(outval, preop); |
| + strcpy(outval, preaction); |
| |
| if (!inval) |
| return 0; |
| + rv = preaction_op_set_val(inval); |
| + if (!rv) |
| + strcpy(preaction, inval); |
| + return 0; |
| +} |
| |
| +static int preop_op_set_val(const char *inval) |
| +{ |
| if (strcmp(inval, "preop_none") == 0) |
| preop_val = WDOG_PREOP_NONE; |
| else if (strcmp(inval, "preop_panic") == 0) |
| @@ -1252,7 +1262,22 @@ static int preop_op(const char *inval, char *outval) |
| preop_val = WDOG_PREOP_GIVE_DATA; |
| else |
| return -EINVAL; |
| - strcpy(preop, inval); |
| + return 0; |
| +} |
| + |
| +static int preop_op(const char *inval, char *outval) |
| +{ |
| + int rv; |
| + |
| + if (outval) |
| + strcpy(outval, preop); |
| + |
| + if (!inval) |
| + return 0; |
| + |
| + rv = preop_op_set_val(inval); |
| + if (!rv) |
| + strcpy(preop, inval); |
| return 0; |
| } |
| |
| @@ -1289,18 +1314,18 @@ static int __init ipmi_wdog_init(void) |
| { |
| int rv; |
| |
| - if (action_op(action, NULL)) { |
| + if (action_op_set_val(action)) { |
| action_op("reset", NULL); |
| pr_info("Unknown action '%s', defaulting to reset\n", action); |
| } |
| |
| - if (preaction_op(preaction, NULL)) { |
| + if (preaction_op_set_val(preaction)) { |
| preaction_op("pre_none", NULL); |
| pr_info("Unknown preaction '%s', defaulting to none\n", |
| preaction); |
| } |
| |
| - if (preop_op(preop, NULL)) { |
| + if (preop_op_set_val(preop)) { |
| preop_op("preop_none", NULL); |
| pr_info("Unknown preop '%s', defaulting to none\n", preop); |
| } |
| -- |
| 2.39.5 |
| |