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: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
Dominik Brodowski 2008-06-19 20:12:34 +02:00
parent c502380170
commit c5081d5f47
7 changed files with 24 additions and 24 deletions

View File

@ -498,17 +498,14 @@ static int pcmciamtd_config(struct pcmcia_device *link)
int i;
config_info_t t;
static char *probes[] = { "jedec_probe", "cfi_probe" };
cisinfo_t cisinfo;
int new_name = 0;
DEBUG(3, "link=0x%p", link);
DEBUG(2, "Validating CIS");
ret = pcmcia_validate_cis(link, &cisinfo);
ret = pcmcia_validate_cis(link, NULL);
if(ret != CS_SUCCESS) {
cs_error(link, GetTupleData, ret);
} else {
DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
}
card_settings(dev, link, &new_name);

View File

@ -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;
cisparse_t *p;
unsigned int count = 0;
int ret, reserved, dev_ok = 0, ident_ok = 0;
if (!s)
@ -1457,7 +1458,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
return CS_OUT_OF_RESOURCE;
}
info->Chains = reserved = 0;
count = reserved = 0;
tuple->DesiredTuple = RETURN_FIRST_TUPLE;
tuple->Attributes = TUPLE_RETURN_COMMON;
ret = pccard_get_first_tuple(s, function, tuple);
@ -1482,7 +1483,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
if (!dev_ok && !ident_ok)
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);
if (ret != CS_SUCCESS) break;
if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
@ -1490,11 +1491,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
reserved++;
}
if ((info->Chains == MAX_TUPLES) || (reserved > 5) ||
((!dev_ok || !ident_ok) && (info->Chains > 10)))
info->Chains = 0;
if ((count) || (reserved > 5) ||
((!dev_ok || !ident_ok) && (count > 10)))
count = 0;
done:
if (info)
*info = count;
kfree(tuple);
kfree(p);
return CS_SUCCESS;

View File

@ -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)
{
cisinfo_t cisinfo;
cistpl_longlink_mfc_t mfc;
unsigned int no_funcs, i;
unsigned int no_funcs, i, no_chains;
int ret = 0;
if (!(s->resource_setup_done)) {
@ -757,8 +756,8 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
return -EAGAIN; /* try again, but later... */
}
ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo);
if (ret || !cisinfo.Chains) {
ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains);
if (ret || !no_chains) {
ds_dbg(0, "invalid CIS or invalid resources\n");
return -ENODEV;
}

View File

@ -735,7 +735,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
mutex_lock(&s->skt_mutex);
pcmcia_validate_mem(s);
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;
case DS_SUSPEND_CARD:
ret = pcmcia_suspend_card(s);

View File

@ -261,21 +261,22 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
======================================================================*/
/* 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;
s->cis_mem.res = res;
s->cis_virt = ioremap(res->start, s->map_size);
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 */
iounmap(s->cis_virt);
s->cis_virt = NULL;
destroy_cis_cache(s);
}
s->cis_mem.res = NULL;
if ((ret != 0) || (info->Chains == 0))
if ((ret != 0) || (count == 0))
return 0;
return 1;
}
@ -316,7 +317,7 @@ static int
cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size)
{
struct resource *res1, *res2;
cisinfo_t info1, info2;
unsigned int info1, info2;
int ret = 0;
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)
free_region(res2);
free_region(res1);
return (ret == 2) && (info1.Chains == info2.Chains);
return (ret == 2) && (info1 == info2);
}
static int

View File

@ -293,7 +293,7 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
count = 0;
else {
struct pcmcia_socket *s;
cisinfo_t cisinfo;
unsigned int chains;
if (off + count > size)
count = size - off;
@ -302,9 +302,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
if (!(s->state & SOCKET_PRESENT))
return -ENODEV;
if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo))
if (pccard_validate_cis(s, BIND_FN_ALL, &chains))
return -EIO;
if (!cisinfo.Chains)
if (!chains)
return -ENODATA;
count = pccard_extract_cis(s, buf, off, count);

View File

@ -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_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 */
#define pcmcia_get_first_tuple(p_dev, tuple) \