Skip to content

Commit bbb4013

Browse files
akky16gregkh
authored andcommitted
misc: amd-sbi: Address copy_to/from_user() warning reported in smatch
Smatch warnings are reported for below commit, Commit bb13a84 ("misc: amd-sbi: Add support for CPUID protocol") from Apr 28, 2025 (linux-next), leads to the following Smatch static checker warning: drivers/misc/amd-sbi/rmi-core.c:376 apml_rmi_reg_xfer() warn: maybe return -EFAULT instead of the bytes remaining? drivers/misc/amd-sbi/rmi-core.c:394 apml_mailbox_xfer() warn: maybe return -EFAULT instead of the bytes remaining? drivers/misc/amd-sbi/rmi-core.c:411 apml_cpuid_xfer() warn: maybe return -EFAULT instead of the bytes remaining? drivers/misc/amd-sbi/rmi-core.c:428 apml_mcamsr_xfer() warn: maybe return -EFAULT instead of the bytes remaining? copy_to/from_user() returns number of bytes, not copied. In case data not copied, return "-EFAULT". Additionally, fixes the "-EPROTOTYPE" error return as intended. Fixes: 35ac203 ("misc: amd-sbi: Add support for AMD_SBI IOCTL") Fixes: bb13a84 ("misc: amd-sbi: Add support for CPUID protocol") Fixes: 69b1ba8 ("misc: amd-sbi: Add support for read MCA register protocol") Fixes: cf14128 ("misc: amd-sbi: Add support for register xfer") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Naveen Krishna Chatradhi <[email protected]> Signed-off-by: Akshay Gupta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e108b0a commit bbb4013

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/misc/amd-sbi/rmi-core.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ static int apml_rmi_reg_xfer(struct sbrmi_data *data,
372372
mutex_unlock(&data->lock);
373373

374374
if (msg.rflag && !ret)
375-
return copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg));
375+
if (copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg)))
376+
return -EFAULT;
376377
return ret;
377378
}
378379

@@ -390,7 +391,9 @@ static int apml_mailbox_xfer(struct sbrmi_data *data, struct apml_mbox_msg __use
390391
if (ret && ret != -EPROTOTYPE)
391392
return ret;
392393

393-
return copy_to_user(arg, &msg, sizeof(struct apml_mbox_msg));
394+
if (copy_to_user(arg, &msg, sizeof(struct apml_mbox_msg)))
395+
return -EFAULT;
396+
return ret;
394397
}
395398

396399
static int apml_cpuid_xfer(struct sbrmi_data *data, struct apml_cpuid_msg __user *arg)
@@ -407,7 +410,9 @@ static int apml_cpuid_xfer(struct sbrmi_data *data, struct apml_cpuid_msg __user
407410
if (ret && ret != -EPROTOTYPE)
408411
return ret;
409412

410-
return copy_to_user(arg, &msg, sizeof(struct apml_cpuid_msg));
413+
if (copy_to_user(arg, &msg, sizeof(struct apml_cpuid_msg)))
414+
return -EFAULT;
415+
return ret;
411416
}
412417

413418
static int apml_mcamsr_xfer(struct sbrmi_data *data, struct apml_mcamsr_msg __user *arg)
@@ -424,7 +429,9 @@ static int apml_mcamsr_xfer(struct sbrmi_data *data, struct apml_mcamsr_msg __us
424429
if (ret && ret != -EPROTOTYPE)
425430
return ret;
426431

427-
return copy_to_user(arg, &msg, sizeof(struct apml_mcamsr_msg));
432+
if (copy_to_user(arg, &msg, sizeof(struct apml_mcamsr_msg)))
433+
return -EFAULT;
434+
return ret;
428435
}
429436

430437
static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)

0 commit comments

Comments
 (0)