[PATCH v2] staging: speakup: remove simple_strtoul()
kbuild test robot
lkp at intel.com
Mon May 28 23:35:44 UTC 2018
Hi Gabriel,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on staging/staging-testing]
[also build test WARNING on v4.17-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Gabriel-Fedel/staging-speakup-remove-simple_strtoul/20180528-231304
coccinelle warnings: (new ones prefixed by >>)
>> drivers/staging/speakup/kobjects.c:163:2-5: alloc with no test, possible model on line 146
drivers/staging/speakup/kobjects.c:163:2-5: alloc with no test, possible model on line 185
drivers/staging/speakup/kobjects.c:809:2-5: alloc with no test, possible model on line 791
vim +163 drivers/staging/speakup/kobjects.c
105
106 /*
107 * This is called when a user changes the characters or chartab parameters.
108 */
109 static ssize_t chars_chartab_store(struct kobject *kobj,
110 struct kobj_attribute *attr,
111 const char *buf, size_t count)
112 {
113 char *cp = (char *)buf;
114 char *end = cp + count; /* the null at the end of the buffer */
115 char *linefeed = NULL;
116 char keyword[MAX_DESC_LEN + 1];
117 char *outptr = NULL; /* Will hold keyword or desc. */
118 char *temp = NULL;
119 char *desc = NULL;
120 char *num = NULL; /* The number part of cp */
121 ssize_t retval = count;
122 unsigned long flags;
123 unsigned long index = 0;
124 int charclass = 0;
125 int received = 0;
126 int used = 0;
127 int rejected = 0;
128 int reset = 0;
129 int do_characters = !strcmp(attr->attr.name, "characters");
130 size_t desc_length = 0;
131 int i;
132
133 spin_lock_irqsave(&speakup_info.spinlock, flags);
134 while (cp < end) {
135 while ((cp < end) && (*cp == ' ' || *cp == '\t'))
136 cp++;
137
138 if (cp == end)
139 break;
140 if ((*cp == '\n') || strchr("dDrR", *cp)) {
141 reset = 1;
142 break;
143 }
144 received++;
145
> 146 linefeed = strchr(cp, '\n');
147 if (!linefeed) {
148 rejected++;
149 break;
150 }
151
152 if (!isdigit(*cp)) {
153 rejected++;
154 cp = linefeed + 1;
155 continue;
156 }
157
158 i = 0;
159 while (isdigit(*(cp + i)))
160 i = i + 1;
161 temp = cp + i;
162
> 163 num = kmalloc(i + 2, GFP_ATOMIC);
164 strscpy(num, cp, i + 1);
165
166 if (kstrtoul(num, 10, &index) != 0)
167 pr_warn("overflow or parsing error has occurred");
168
169 if (index > 255) {
170 rejected++;
171 cp = linefeed + 1;
172 continue;
173 }
174
175 while ((temp < linefeed) && (*temp == ' ' || *temp == '\t'))
176 temp++;
177
178 desc_length = linefeed - temp;
179 if (desc_length > MAX_DESC_LEN) {
180 rejected++;
181 cp = linefeed + 1;
182 continue;
183 }
184 if (do_characters) {
185 desc = kmalloc(desc_length + 1, GFP_ATOMIC);
186 if (!desc) {
187 retval = -ENOMEM;
188 reset = 1; /* just reset on error. */
189 break;
190 }
191 outptr = desc;
192 } else {
193 outptr = keyword;
194 }
195
196 for (i = 0; i < desc_length; i++)
197 outptr[i] = temp[i];
198 outptr[desc_length] = '\0';
199
200 if (do_characters) {
201 if (spk_characters[index] != spk_default_chars[index])
202 kfree(spk_characters[index]);
203 spk_characters[index] = desc;
204 used++;
205 } else {
206 charclass = spk_chartab_get_value(keyword);
207 if (charclass == 0) {
208 rejected++;
209 cp = linefeed + 1;
210 continue;
211 }
212 if (charclass != spk_chartab[index]) {
213 spk_chartab[index] = charclass;
214 used++;
215 }
216 }
217 cp = linefeed + 1;
218 }
219
220 if (reset) {
221 if (do_characters)
222 spk_reset_default_chars();
223 else
224 spk_reset_default_chartab();
225 }
226
227 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
228 report_char_chartab_status(reset, received, used, rejected,
229 do_characters);
230 return retval;
231 }
232
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
More information about the devel
mailing list