Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+12 -15
+12 -15
drivers/pcmcia/socket_sysfs.c
··· 298 298 { 299 299 struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj)); 300 300 cisdump_t *cis; 301 - ssize_t ret = count; 301 + int error; 302 302 303 303 if (off) 304 304 return -EINVAL; ··· 316 316 cis->Length = count + 1; 317 317 memcpy(cis->Data, buf, count); 318 318 319 - if (pcmcia_replace_cis(s, cis)) 320 - ret = -EIO; 321 - 319 + error = pcmcia_replace_cis(s, cis); 322 320 kfree(cis); 321 + if (error) 322 + return -EIO; 323 323 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); 332 330 } 333 - mutex_unlock(&s->skt_mutex); 334 331 } 332 + mutex_unlock(&s->skt_mutex); 335 333 336 - 337 - return (ret); 334 + return count; 338 335 } 339 336 340 337