Commit f131ddc4 authored by Dominik Brodowski's avatar Dominik Brodowski

pcmcia: cleanup pccard_validate_cis()

Cleanup pccard_validate_cis() and make it return an error code on
all failures, not merely on some failures.
Tested-by: default avatarWolfram Sang <w.sang@pengutronix.de>
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent 904e3777
...@@ -1577,16 +1577,19 @@ int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, ...@@ -1577,16 +1577,19 @@ int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
EXPORT_SYMBOL(pccard_loop_tuple); EXPORT_SYMBOL(pccard_loop_tuple);
/*====================================================================== /**
* pccard_validate_cis() - check whether card has a sensible CIS
This tries to determine if a card has a sensible CIS. It returns * @s: the struct pcmcia_socket we are to check
the number of tuples in the CIS, or 0 if the CIS looks bad. The * @info: returns the number of tuples in the (valid) CIS, or 0
checks include making sure several critical tuples are present and *
valid; seeing if the total number of tuples is reasonable; and * This tries to determine if a card has a sensible CIS. In @info, it
looking for tuples that use reserved codes. * returns the number of tuples in the CIS, or 0 if the CIS looks bad. The
* checks include making sure several critical tuples are present and
======================================================================*/ * valid; seeing if the total number of tuples is reasonable; and
* looking for tuples that use reserved codes.
*
* The function returns 0 on success.
*/
int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
{ {
tuple_t *tuple; tuple_t *tuple;
...@@ -1602,13 +1605,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) ...@@ -1602,13 +1605,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
if (tuple == NULL) { if (tuple == NULL) {
dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); dev_warn(&s->dev, "no memory to validate CIS\n");
return -ENOMEM; return -ENOMEM;
} }
p = kmalloc(sizeof(*p), GFP_KERNEL); p = kmalloc(sizeof(*p), GFP_KERNEL);
if (p == NULL) { if (p == NULL) {
kfree(tuple); kfree(tuple);
dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); dev_warn(&s->dev, "no memory to validate CIS\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -1622,8 +1625,8 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) ...@@ -1622,8 +1625,8 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
/* First tuple should be DEVICE; we should really have either that /* First tuple should be DEVICE; we should really have either that
or a CFTABLE_ENTRY of some sort */ or a CFTABLE_ENTRY of some sort */
if ((tuple->TupleCode == CISTPL_DEVICE) || if ((tuple->TupleCode == CISTPL_DEVICE) ||
(pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p) == 0) || (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p)) ||
(pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p)))
dev_ok++; dev_ok++;
/* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
...@@ -1650,15 +1653,19 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) ...@@ -1650,15 +1653,19 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
((!dev_ok || !ident_ok) && (count > 10))) ((!dev_ok || !ident_ok) && (count > 10)))
count = 0; count = 0;
ret = 0;
done: done:
/* invalidate CIS cache on failure */ /* invalidate CIS cache on failure */
if (!dev_ok || !ident_ok || !count) if (!dev_ok || !ident_ok || !count) {
destroy_cis_cache(s); destroy_cis_cache(s);
ret = -EIO;
}
if (info) if (info)
*info = count; *info = count;
kfree(tuple); kfree(tuple);
kfree(p); kfree(p);
return 0; return ret;
} }
EXPORT_SYMBOL(pccard_validate_cis); EXPORT_SYMBOL(pccard_validate_cis);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment