Commit c5081d5f authored by Dominik Brodowski's avatar Dominik Brodowski

pcmcia: simplify pccard_validate_cis

As cisinfo_t only contains one unsigned_int, pccard_validate_cis can
be simplified by passing that around directly.
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent c5023801
...@@ -498,17 +498,14 @@ static int pcmciamtd_config(struct pcmcia_device *link) ...@@ -498,17 +498,14 @@ static int pcmciamtd_config(struct pcmcia_device *link)
int i; int i;
config_info_t t; config_info_t t;
static char *probes[] = { "jedec_probe", "cfi_probe" }; static char *probes[] = { "jedec_probe", "cfi_probe" };
cisinfo_t cisinfo;
int new_name = 0; int new_name = 0;
DEBUG(3, "link=0x%p", link); DEBUG(3, "link=0x%p", link);
DEBUG(2, "Validating CIS"); DEBUG(2, "Validating CIS");
ret = pcmcia_validate_cis(link, &cisinfo); ret = pcmcia_validate_cis(link, NULL);
if(ret != CS_SUCCESS) { if(ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret); cs_error(link, GetTupleData, ret);
} else {
DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
} }
card_settings(dev, link, &new_name); card_settings(dev, link, &new_name);
......
...@@ -1439,10 +1439,11 @@ EXPORT_SYMBOL(pccard_read_tuple); ...@@ -1439,10 +1439,11 @@ EXPORT_SYMBOL(pccard_read_tuple);
======================================================================*/ ======================================================================*/
int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_t *info) int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned int *info)
{ {
tuple_t *tuple; tuple_t *tuple;
cisparse_t *p; cisparse_t *p;
unsigned int count = 0;
int ret, reserved, dev_ok = 0, ident_ok = 0; int ret, reserved, dev_ok = 0, ident_ok = 0;
if (!s) if (!s)
...@@ -1457,7 +1458,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_ ...@@ -1457,7 +1458,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
return CS_OUT_OF_RESOURCE; return CS_OUT_OF_RESOURCE;
} }
info->Chains = reserved = 0; count = reserved = 0;
tuple->DesiredTuple = RETURN_FIRST_TUPLE; tuple->DesiredTuple = RETURN_FIRST_TUPLE;
tuple->Attributes = TUPLE_RETURN_COMMON; tuple->Attributes = TUPLE_RETURN_COMMON;
ret = pccard_get_first_tuple(s, function, tuple); ret = pccard_get_first_tuple(s, function, tuple);
...@@ -1482,7 +1483,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_ ...@@ -1482,7 +1483,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
if (!dev_ok && !ident_ok) if (!dev_ok && !ident_ok)
goto done; goto done;
for (info->Chains = 1; info->Chains < MAX_TUPLES; info->Chains++) { for (count = 1; count < MAX_TUPLES; count++) {
ret = pccard_get_next_tuple(s, function, tuple); ret = pccard_get_next_tuple(s, function, tuple);
if (ret != CS_SUCCESS) break; if (ret != CS_SUCCESS) break;
if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
...@@ -1490,11 +1491,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_ ...@@ -1490,11 +1491,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
reserved++; reserved++;
} }
if ((info->Chains == MAX_TUPLES) || (reserved > 5) || if ((count) || (reserved > 5) ||
((!dev_ok || !ident_ok) && (info->Chains > 10))) ((!dev_ok || !ident_ok) && (count > 10)))
info->Chains = 0; count = 0;
done: done:
if (info)
*info = count;
kfree(tuple); kfree(tuple);
kfree(p); kfree(p);
return CS_SUCCESS; return CS_SUCCESS;
......
...@@ -741,9 +741,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f ...@@ -741,9 +741,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
static int pcmcia_card_add(struct pcmcia_socket *s) static int pcmcia_card_add(struct pcmcia_socket *s)
{ {
cisinfo_t cisinfo;
cistpl_longlink_mfc_t mfc; cistpl_longlink_mfc_t mfc;
unsigned int no_funcs, i; unsigned int no_funcs, i, no_chains;
int ret = 0; int ret = 0;
if (!(s->resource_setup_done)) { if (!(s->resource_setup_done)) {
...@@ -757,8 +756,8 @@ static int pcmcia_card_add(struct pcmcia_socket *s) ...@@ -757,8 +756,8 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
return -EAGAIN; /* try again, but later... */ return -EAGAIN; /* try again, but later... */
} }
ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo); ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains);
if (ret || !cisinfo.Chains) { if (ret || !no_chains) {
ds_dbg(0, "invalid CIS or invalid resources\n"); ds_dbg(0, "invalid CIS or invalid resources\n");
return -ENODEV; return -ENODEV;
} }
......
...@@ -735,7 +735,7 @@ static int ds_ioctl(struct inode * inode, struct file * file, ...@@ -735,7 +735,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
mutex_lock(&s->skt_mutex); mutex_lock(&s->skt_mutex);
pcmcia_validate_mem(s); pcmcia_validate_mem(s);
mutex_unlock(&s->skt_mutex); mutex_unlock(&s->skt_mutex);
ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo); ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo.Chains);
break; break;
case DS_SUSPEND_CARD: case DS_SUSPEND_CARD:
ret = pcmcia_suspend_card(s); ret = pcmcia_suspend_card(s);
......
...@@ -261,21 +261,22 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base, ...@@ -261,21 +261,22 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
======================================================================*/ ======================================================================*/
/* Validation function for cards with a valid CIS */ /* Validation function for cards with a valid CIS */
static int readable(struct pcmcia_socket *s, struct resource *res, cisinfo_t *info) static int readable(struct pcmcia_socket *s, struct resource *res,
unsigned int *count)
{ {
int ret = -1; int ret = -1;
s->cis_mem.res = res; s->cis_mem.res = res;
s->cis_virt = ioremap(res->start, s->map_size); s->cis_virt = ioremap(res->start, s->map_size);
if (s->cis_virt) { if (s->cis_virt) {
ret = pccard_validate_cis(s, BIND_FN_ALL, info); ret = pccard_validate_cis(s, BIND_FN_ALL, count);
/* invalidate mapping and CIS cache */ /* invalidate mapping and CIS cache */
iounmap(s->cis_virt); iounmap(s->cis_virt);
s->cis_virt = NULL; s->cis_virt = NULL;
destroy_cis_cache(s); destroy_cis_cache(s);
} }
s->cis_mem.res = NULL; s->cis_mem.res = NULL;
if ((ret != 0) || (info->Chains == 0)) if ((ret != 0) || (count == 0))
return 0; return 0;
return 1; return 1;
} }
...@@ -316,7 +317,7 @@ static int ...@@ -316,7 +317,7 @@ static int
cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size) cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size)
{ {
struct resource *res1, *res2; struct resource *res1, *res2;
cisinfo_t info1, info2; unsigned int info1, info2;
int ret = 0; int ret = 0;
res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "cs memory probe"); res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "cs memory probe");
...@@ -330,7 +331,7 @@ cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size) ...@@ -330,7 +331,7 @@ cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size)
free_region(res2); free_region(res2);
free_region(res1); free_region(res1);
return (ret == 2) && (info1.Chains == info2.Chains); return (ret == 2) && (info1 == info2);
} }
static int static int
......
...@@ -293,7 +293,7 @@ static ssize_t pccard_show_cis(struct kobject *kobj, ...@@ -293,7 +293,7 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
count = 0; count = 0;
else { else {
struct pcmcia_socket *s; struct pcmcia_socket *s;
cisinfo_t cisinfo; unsigned int chains;
if (off + count > size) if (off + count > size)
count = size - off; count = size - off;
...@@ -302,9 +302,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj, ...@@ -302,9 +302,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
if (!(s->state & SOCKET_PRESENT)) if (!(s->state & SOCKET_PRESENT))
return -ENODEV; return -ENODEV;
if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo)) if (pccard_validate_cis(s, BIND_FN_ALL, &chains))
return -EIO; return -EIO;
if (!cisinfo.Chains) if (!chains)
return -ENODATA; return -ENODATA;
count = pccard_extract_cis(s, buf, off, count); count = pccard_extract_cis(s, buf, off, count);
......
...@@ -595,7 +595,7 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple ...@@ -595,7 +595,7 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse); int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse);
int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_t *info); int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned int *count);
/* ... but use these wrappers instead */ /* ... but use these wrappers instead */
#define pcmcia_get_first_tuple(p_dev, tuple) \ #define pcmcia_get_first_tuple(p_dev, tuple) \
......
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