mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] s390: net: claw.c:  Cleaning up possible error if incorrect in parameter
@ 2014-07-30 20:32 Rickard Strandqvist
  2014-07-31  7:36 ` Ursula Braun
  0 siblings, 1 reply; 2+ messages in thread
From: Rickard Strandqvist @ 2014-07-30 20:32 UTC (permalink / raw)
  To: Ursula Braun, Frank Blaschka
  Cc: Rickard Strandqvist, linux390, Martin Schwidefsky,
	Heiko Carstens, linux-s390, linux-kernel

Possible error if incorrect in parameter, count = 0.
And clarified what the code actually does significantly.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/s390/net/claw.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index d837c3c..8d5b7b6 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -3070,10 +3070,10 @@ claw_hname_write(struct device *dev, struct device_attribute *attr,
 	p_env = priv->p_env;
 	if (count > MAX_NAME_LEN+1)
 		return -EINVAL;
-	memset(p_env->host_name, 0x20, MAX_NAME_LEN);
-	strncpy(p_env->host_name,buf, count);
-	p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */
-	p_env->host_name[MAX_NAME_LEN] = 0x00;
+	strlcpy(p_env->host_name, buf,
+			sizeof(p_env->host_name));
+	strlcat(p_env->host_name, "        ",
+			sizeof(p_env->host_name));
 	CLAW_DBF_TEXT(2, setup, "HstnSet");
 	CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
 
@@ -3108,10 +3108,10 @@ claw_adname_write(struct device *dev, struct device_attribute *attr,
 	p_env = priv->p_env;
 	if (count > MAX_NAME_LEN+1)
 		return -EINVAL;
-	memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
-	strncpy(p_env->adapter_name,buf, count);
-	p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
-	p_env->adapter_name[MAX_NAME_LEN] = 0x00;
+	strlcpy(p_env->adapter_name, buf,
+			sizeof(p_env->adapter_name));
+	strlcat(p_env->adapter_name, "        ",
+			sizeof(p_env->adapter_name));
 	CLAW_DBF_TEXT(2, setup, "AdnSet");
 	CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
 
@@ -3147,10 +3147,10 @@ claw_apname_write(struct device *dev, struct device_attribute *attr,
 	p_env = priv->p_env;
 	if (count > MAX_NAME_LEN+1)
 		return -EINVAL;
-	memset(p_env->api_type, 0x20, MAX_NAME_LEN);
-	strncpy(p_env->api_type,buf, count);
-	p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */
-	p_env->api_type[MAX_NAME_LEN] = 0x00;
+	strlcpy(p_env->api_type, buf,
+			sizeof(p_env->api_type));
+	strlcat(p_env->api_type, "        ",
+			sizeof(p_env->api_type));
 	if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
 		p_env->read_size=DEF_PACK_BUFSIZE;
 		p_env->write_size=DEF_PACK_BUFSIZE;
-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] s390: net: claw.c:  Cleaning up possible error if incorrect in parameter
  2014-07-30 20:32 [PATCH] s390: net: claw.c: Cleaning up possible error if incorrect in parameter Rickard Strandqvist
@ 2014-07-31  7:36 ` Ursula Braun
  0 siblings, 0 replies; 2+ messages in thread
From: Ursula Braun @ 2014-07-31  7:36 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Ursula Braun, Frank Blaschka, linux390, Martin Schwidefsky,
	Heiko Carstens, linux-s390, linux-kernel

On Wed, 2014-07-30 at 22:32 +0200, Rickard Strandqvist wrote:
> Possible error if incorrect in parameter, count = 0.
> And clarified what the code actually does significantly.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  drivers/s390/net/claw.c |   24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
> index d837c3c..8d5b7b6 100644
> --- a/drivers/s390/net/claw.c
> +++ b/drivers/s390/net/claw.c
> @@ -3070,10 +3070,10 @@ claw_hname_write(struct device *dev, struct device_attribute *attr,
>  	p_env = priv->p_env;
>  	if (count > MAX_NAME_LEN+1)
>  		return -EINVAL;
> -	memset(p_env->host_name, 0x20, MAX_NAME_LEN);
> -	strncpy(p_env->host_name,buf, count);
> -	p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */
> -	p_env->host_name[MAX_NAME_LEN] = 0x00;
> +	strlcpy(p_env->host_name, buf,
> +			sizeof(p_env->host_name));
> +	strlcat(p_env->host_name, "        ",
> +			sizeof(p_env->host_name));
>  	CLAW_DBF_TEXT(2, setup, "HstnSet");
>  	CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
> 
> @@ -3108,10 +3108,10 @@ claw_adname_write(struct device *dev, struct device_attribute *attr,
>  	p_env = priv->p_env;
>  	if (count > MAX_NAME_LEN+1)
>  		return -EINVAL;
> -	memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
> -	strncpy(p_env->adapter_name,buf, count);
> -	p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
> -	p_env->adapter_name[MAX_NAME_LEN] = 0x00;
> +	strlcpy(p_env->adapter_name, buf,
> +			sizeof(p_env->adapter_name));
> +	strlcat(p_env->adapter_name, "        ",
> +			sizeof(p_env->adapter_name));
>  	CLAW_DBF_TEXT(2, setup, "AdnSet");
>  	CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
> 
> @@ -3147,10 +3147,10 @@ claw_apname_write(struct device *dev, struct device_attribute *attr,
>  	p_env = priv->p_env;
>  	if (count > MAX_NAME_LEN+1)
>  		return -EINVAL;
> -	memset(p_env->api_type, 0x20, MAX_NAME_LEN);
> -	strncpy(p_env->api_type,buf, count);
> -	p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */
> -	p_env->api_type[MAX_NAME_LEN] = 0x00;
> +	strlcpy(p_env->api_type, buf,
> +			sizeof(p_env->api_type));
> +	strlcat(p_env->api_type, "        ",
> +			sizeof(p_env->api_type));
>  	if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
>  		p_env->read_size=DEF_PACK_BUFSIZE;
>  		p_env->write_size=DEF_PACK_BUFSIZE;

These functions are invoked when echoing something into a sysfs
attribute. The smallest count value possible here is 1, i.e. just a
linefeed.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-07-31  7:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-30 20:32 [PATCH] s390: net: claw.c: Cleaning up possible error if incorrect in parameter Rickard Strandqvist
2014-07-31  7:36 ` Ursula Braun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®