Skip to content

Commit d834c16

Browse files
author
Linus Torvalds
committed
pccard_store_cis: fix wrong error handling
The test for the error from pcmcia_replace_cis() was incorrect, and would always trigger (because if an error didn't happen, the "ret" value would not be zero, it would be the passed-in count). Reported and debugged by Fabrice Bellet <fabrice@bellet.info> Rather than just fix the single broken test, make the code in question use an understandable code-sequence instead, fixing the whole function to be more readable. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 4e9011d commit d834c16

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

‎drivers/pcmcia/socket_sysfs.c‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
298298
{
299299
struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj));
300300
cisdump_t *cis;
301-
ssize_t ret = count;
301+
int error;
302302

303303
if (off)
304304
return -EINVAL;
@@ -316,25 +316,22 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
316316
cis->Length = count + 1;
317317
memcpy(cis->Data, buf, count);
318318

319-
if (pcmcia_replace_cis(s, cis))
320-
ret = -EIO;
321-
319+
error = pcmcia_replace_cis(s, cis);
322320
kfree(cis);
321+
if (error)
322+
return -EIO;
323323

324-
if (!ret) {
325-
mutex_lock(&s->skt_mutex);
326-
if ((s->callback) && (s->state & SOCKET_PRESENT) &&
327-
!(s->state & SOCKET_CARDBUS)) {
328-
if (try_module_get(s->callback->owner)) {
329-
s->callback->requery(s);
330-
module_put(s->callback->owner);
331-
}
324+
mutex_lock(&s->skt_mutex);
325+
if ((s->callback) && (s->state & SOCKET_PRESENT) &&
326+
!(s->state & SOCKET_CARDBUS)) {
327+
if (try_module_get(s->callback->owner)) {
328+
s->callback->requery(s);
329+
module_put(s->callback->owner);
332330
}
333-
mutex_unlock(&s->skt_mutex);
334331
}
332+
mutex_unlock(&s->skt_mutex);
335333

336-
337-
return (ret);
334+
return count;
338335
}
339336

340337

0 commit comments

Comments
 (0)