public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux•com>
To: "Chas Williams (CONTRACTOR)" <chas@cmf•nrl.navy.mil>
Cc: David Miller <davem@davemloft•net>, netdev <netdev@vger•kernel.org>
Subject: Re: [Suggestion] net/atm : for sprintf, need check the total write length whether larger than a page.
Date: Wed, 05 Dec 2012 09:26:35 +0800	[thread overview]
Message-ID: <50BEA2CB.9000800@asianux.com> (raw)
In-Reply-To: <201212040346.qB43kVSQ018028@thirdoffive.cmf.nrl.navy.mil>


  firstly, sorry for reply late (yesterday I have an annual leave for
some personal things).

  and thank you for your reply, too.


于 2012年12月04日 11:46, Chas Williams (CONTRACTOR) 写道:
>  static ssize_t show_address(struct device *cdev,
>  			    struct device_attribute *attr, char *buf)
>  {
> -	char *pos = buf;
>  	struct atm_dev *adev = to_atm_dev(cdev);
> -	int i;
> -
> -	for (i = 0; i < (ESI_LEN - 1); i++)
> -		pos += sprintf(pos, "%02x:", adev->esi[i]);
> -	pos += sprintf(pos, "%02x\n", adev->esi[i]);
>  
> -	return pos - buf;
> +	return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
>  }
>  

  "%p" seems print a pointer, not contents of pointer (is it correct ?)

  will it change the original display format to outside ?


>  static ssize_t show_atmaddress(struct device *cdev,
>  			       struct device_attribute *attr, char *buf)
>  {
>  	unsigned long flags;
> -	char *pos = buf;
>  	struct atm_dev *adev = to_atm_dev(cdev);
>  	struct atm_dev_addr *aaddr;
>  	int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin;
> -	int i, j;
> +	int i, j, count = 0;
>  
>  	spin_lock_irqsave(&adev->lock, flags);
>  	list_for_each_entry(aaddr, &adev->local, entry) {
>  		for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
>  			if (j == *fmt) {
> -				pos += sprintf(pos, ".");
> +				count += scnprintf(buf + count,
> +						   PAGE_SIZE - count, ".");
>  				++fmt;
>  				j = 0;
>  			}
> -			pos += sprintf(pos, "%02x",
> -				       aaddr->addr.sas_addr.prv[i]);
> +			count += scnprintf(buf + count,
> +					   PAGE_SIZE - count, "%02x",
> +					   aaddr->addr.sas_addr.prv[i]);
>  		}
> -		pos += sprintf(pos, "\n");
> +		count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
>  	}
>  	spin_unlock_irqrestore(&adev->lock, flags);
>  
> -	return pos - buf;
> +	return count;
>  }
>  

  need we judge whether count >= PAGE_SIZE ?


  these are my suggestions, maybe not correct.

  :-)

  thanks.

-- 
Chen Gang

Asianux Corporation

  reply	other threads:[~2012-12-05  1:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21  4:29 [Suggestion] net/atm : for sprintf, need check the total write length whether larger than a page Chen Gang
2012-12-03  8:56 ` Chen Gang
2012-12-03 15:48   ` chas williams - CONTRACTOR
2012-12-05  1:28     ` Chen Gang
2012-12-04  3:46 ` Chas Williams (CONTRACTOR)
2012-12-05  1:26   ` Chen Gang [this message]
2012-12-05  3:57     ` Chas Williams (CONTRACTOR)
2012-12-05  4:56       ` Chen Gang
2012-12-05  5:40         ` Chen Gang
2012-12-05  5:59           ` Chen Gang
2012-12-05 14:55             ` chas williams - CONTRACTOR
2012-12-06  1:15               ` Chen Gang
2012-12-06  9:05                 ` Chen Gang
2012-12-06 14:08                 ` chas williams - CONTRACTOR
2012-12-07  1:07                   ` Chen Gang
2012-12-10  1:39                     ` Chen Gang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50BEA2CB.9000800@asianux.com \
    --to=gang.chen@asianux$(echo .)com \
    --cc=chas@cmf$(echo .)nrl.navy.mil \
    --cc=davem@davemloft$(echo .)net \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox