aboutsummaryrefslogtreecommitdiffstats
path: root/net/atm/atm_sysfs.c
diff options
context:
space:
mode:
authorchas williams - CONTRACTOR <chas@cmf.nrl.navy.mil>2012-12-17 01:00:01 -0500
committerDavid S. Miller <davem@davemloft.net>2012-12-17 23:50:51 -0500
commit3c4177716cd2e452229dd0b7c25d192c48c1e7ac (patch)
treedf6fad87e61b45af98d0a2a540bf07318b4a4f7f /net/atm/atm_sysfs.c
parent4e4b53768f1ddce38b7f6edcad3a063020ef0024 (diff)
atm: use scnprintf() instead of sprintf()
As reported by Chen Gang <gang.chen@asianux.com>, we should ensure there is enough space when formatting the sysfs buffers. Signed-off-by: Chas Williams <chas@cmf.nrl.navy.mil> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/atm/atm_sysfs.c')
-rw-r--r--net/atm/atm_sysfs.c40
1 files changed, 15 insertions, 25 deletions
diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c
index f49da5814bc3..350bf62b2ae3 100644
--- a/net/atm/atm_sysfs.c
+++ b/net/atm/atm_sysfs.c
@@ -14,49 +14,45 @@ static ssize_t show_type(struct device *cdev,
14 struct device_attribute *attr, char *buf) 14 struct device_attribute *attr, char *buf)
15{ 15{
16 struct atm_dev *adev = to_atm_dev(cdev); 16 struct atm_dev *adev = to_atm_dev(cdev);
17 return sprintf(buf, "%s\n", adev->type); 17
18 return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
18} 19}
19 20
20static ssize_t show_address(struct device *cdev, 21static ssize_t show_address(struct device *cdev,
21 struct device_attribute *attr, char *buf) 22 struct device_attribute *attr, char *buf)
22{ 23{
23 char *pos = buf;
24 struct atm_dev *adev = to_atm_dev(cdev); 24 struct atm_dev *adev = to_atm_dev(cdev);
25 int i;
26
27 for (i = 0; i < (ESI_LEN - 1); i++)
28 pos += sprintf(pos, "%02x:", adev->esi[i]);
29 pos += sprintf(pos, "%02x\n", adev->esi[i]);
30 25
31 return pos - buf; 26 return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
32} 27}
33 28
34static ssize_t show_atmaddress(struct device *cdev, 29static ssize_t show_atmaddress(struct device *cdev,
35 struct device_attribute *attr, char *buf) 30 struct device_attribute *attr, char *buf)
36{ 31{
37 unsigned long flags; 32 unsigned long flags;
38 char *pos = buf;
39 struct atm_dev *adev = to_atm_dev(cdev); 33 struct atm_dev *adev = to_atm_dev(cdev);
40 struct atm_dev_addr *aaddr; 34 struct atm_dev_addr *aaddr;
41 int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin; 35 int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin;
42 int i, j; 36 int i, j, count = 0;
43 37
44 spin_lock_irqsave(&adev->lock, flags); 38 spin_lock_irqsave(&adev->lock, flags);
45 list_for_each_entry(aaddr, &adev->local, entry) { 39 list_for_each_entry(aaddr, &adev->local, entry) {
46 for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) { 40 for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
47 if (j == *fmt) { 41 if (j == *fmt) {
48 pos += sprintf(pos, "."); 42 count += scnprintf(buf + count,
43 PAGE_SIZE - count, ".");
49 ++fmt; 44 ++fmt;
50 j = 0; 45 j = 0;
51 } 46 }
52 pos += sprintf(pos, "%02x", 47 count += scnprintf(buf + count,
53 aaddr->addr.sas_addr.prv[i]); 48 PAGE_SIZE - count, "%02x",
49 aaddr->addr.sas_addr.prv[i]);
54 } 50 }
55 pos += sprintf(pos, "\n"); 51 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
56 } 52 }
57 spin_unlock_irqrestore(&adev->lock, flags); 53 spin_unlock_irqrestore(&adev->lock, flags);
58 54
59 return pos - buf; 55 return count;
60} 56}
61 57
62static ssize_t show_atmindex(struct device *cdev, 58static ssize_t show_atmindex(struct device *cdev,
@@ -64,25 +60,21 @@ static ssize_t show_atmindex(struct device *cdev,
64{ 60{
65 struct atm_dev *adev = to_atm_dev(cdev); 61 struct atm_dev *adev = to_atm_dev(cdev);
66 62
67 return sprintf(buf, "%d\n", adev->number); 63 return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
68} 64}
69 65
70static ssize_t show_carrier(struct device *cdev, 66static ssize_t show_carrier(struct device *cdev,
71 struct device_attribute *attr, char *buf) 67 struct device_attribute *attr, char *buf)
72{ 68{
73 char *pos = buf;
74 struct atm_dev *adev = to_atm_dev(cdev); 69 struct atm_dev *adev = to_atm_dev(cdev);
75 70
76 pos += sprintf(pos, "%d\n", 71 return scnprintf(buf, PAGE_SIZE, "%d\n",
77 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1); 72 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
78
79 return pos - buf;
80} 73}
81 74
82static ssize_t show_link_rate(struct device *cdev, 75static ssize_t show_link_rate(struct device *cdev,
83 struct device_attribute *attr, char *buf) 76 struct device_attribute *attr, char *buf)
84{ 77{
85 char *pos = buf;
86 struct atm_dev *adev = to_atm_dev(cdev); 78 struct atm_dev *adev = to_atm_dev(cdev);
87 int link_rate; 79 int link_rate;
88 80
@@ -100,9 +92,7 @@ static ssize_t show_link_rate(struct device *cdev,
100 default: 92 default:
101 link_rate = adev->link_rate * 8 * 53; 93 link_rate = adev->link_rate * 8 * 53;
102 } 94 }
103 pos += sprintf(pos, "%d\n", link_rate); 95 return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
104
105 return pos - buf;
106} 96}
107 97
108static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); 98static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);