Skip to content

Commit

Permalink
pcmcia: simplify pccard_validate_cis
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dominik Brodowski committed Jun 24, 2008
1 parent c502380 commit c5081d5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
5 changes: 1 addition & 4 deletions drivers/mtd/maps/pcmciamtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions drivers/pcmcia/cistpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -1482,19 +1483,21 @@ 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)) ||
((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) ||
((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;
Expand Down
7 changes: 3 additions & 4 deletions drivers/pcmcia/ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/pcmcia/pcmcia_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions drivers/pcmcia/rsrc_nonstatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions drivers/pcmcia/socket_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/pcmcia/cistpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit c5081d5

Please sign in to comment.