Skip to content

Commit

Permalink
pccard_store_cis: fix wrong error handling
Browse files Browse the repository at this point in the history
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 <[email protected]>

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 <[email protected]>
  • Loading branch information
Linus Torvalds committed Oct 1, 2006
1 parent 4e9011d commit d834c16
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions drivers/pcmcia/socket_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
{
struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj));
cisdump_t *cis;
ssize_t ret = count;
int error;

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

if (pcmcia_replace_cis(s, cis))
ret = -EIO;

error = pcmcia_replace_cis(s, cis);
kfree(cis);
if (error)
return -EIO;

if (!ret) {
mutex_lock(&s->skt_mutex);
if ((s->callback) && (s->state & SOCKET_PRESENT) &&
!(s->state & SOCKET_CARDBUS)) {
if (try_module_get(s->callback->owner)) {
s->callback->requery(s);
module_put(s->callback->owner);
}
mutex_lock(&s->skt_mutex);
if ((s->callback) && (s->state & SOCKET_PRESENT) &&
!(s->state & SOCKET_CARDBUS)) {
if (try_module_get(s->callback->owner)) {
s->callback->requery(s);
module_put(s->callback->owner);
}
mutex_unlock(&s->skt_mutex);
}
mutex_unlock(&s->skt_mutex);


return (ret);
return count;
}


Expand Down

0 comments on commit d834c16

Please sign in to comment.