diff mbox series

[net-next] net: dsa: microchip: ptp: Fix error code in ksz_hwtstamp_set()

Message ID Y8fJxSvbl7UNVHh/@kili (mailing list archive)
State Accepted
Commit a76e88c2942575bc43ea88d0f05d245b26859130
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dsa: microchip: ptp: Fix error code in ksz_hwtstamp_set() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 13 of 13 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter Jan. 18, 2023, 10:28 a.m. UTC
We want to return negative error codes here but the copy_to/from_user()
functions return the number of bytes remaining to be copied.

Fixes: c59e12a140fb ("net: dsa: microchip: ptp: Initial hardware time stamping support")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/net/dsa/microchip/ksz_ptp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Vladimir Oltean Jan. 18, 2023, 10:44 a.m. UTC | #1
On Wed, Jan 18, 2023 at 01:28:21PM +0300, Dan Carpenter wrote:
> We want to return negative error codes here but the copy_to/from_user()
> functions return the number of bytes remaining to be copied.
> 
> Fixes: c59e12a140fb ("net: dsa: microchip: ptp: Initial hardware time stamping support")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
patchwork-bot+netdevbpf@kernel.org Jan. 20, 2023, 3 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 18 Jan 2023 13:28:21 +0300 you wrote:
> We want to return negative error codes here but the copy_to/from_user()
> functions return the number of bytes remaining to be copied.
> 
> Fixes: c59e12a140fb ("net: dsa: microchip: ptp: Initial hardware time stamping support")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>  drivers/net/dsa/microchip/ksz_ptp.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [net-next] net: dsa: microchip: ptp: Fix error code in ksz_hwtstamp_set()
    https://git.kernel.org/netdev/net-next/c/a76e88c29425

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
index a66a256f8814..4e22a695a64c 100644
--- a/drivers/net/dsa/microchip/ksz_ptp.c
+++ b/drivers/net/dsa/microchip/ksz_ptp.c
@@ -416,9 +416,8 @@  int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr)
 
 	prt = &dev->ports[port];
 
-	ret = copy_from_user(&config, ifr->ifr_data, sizeof(config));
-	if (ret)
-		return ret;
+	if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
+		return -EFAULT;
 
 	ret = ksz_set_hwtstamp_config(dev, prt, &config);
 	if (ret)
@@ -426,7 +425,10 @@  int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr)
 
 	memcpy(&prt->tstamp_config, &config, sizeof(config));
 
-	return copy_to_user(ifr->ifr_data, &config, sizeof(config));
+	if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
+		return -EFAULT;
+
+	return 0;
 }
 
 static ktime_t ksz_tstamp_reconstruct(struct ksz_device *dev, ktime_t tstamp)