[PATCH 5/5] card insert / eject

Russell King rmk+pcmcia at arm.linux.org.uk
Tue May 18 20:53:57 BST 2004


On Tue, May 11, 2004 at 09:28:50PM +0200, Dominik Brodowski wrote:
> Add two further attributes, "card_insert" and "card_eject". Reading these
> files will fail; but writing _anything_ non-empty to these files will execute
> an user insert/ejection request -- equivalent to "cardctl insert", 
> "cardctl eject".

There's something else weird here.

> +
> +static ssize_t pccard_store_insert(struct class_device *dev, const char *buf, size_t count)
> +{
> +	ssize_t ret;
> +	struct pcmcia_socket *s = to_socket(dev);
> +
> +	if (s->state & SOCKET_PRESENT)
> +		return -EINVAL;

This introduces a nice race condition - pcmcia_insert_card already checks
this in a race-free manner so I suggest deleting this test.

> +	if (!count)
> +		return -EINVAL;
> +
> +	ret = pcmcia_insert_card(s);

Also, pcmcia_insert_card() returns 0 for success, non-zero positive for
failure, which means that:

> +
> +	return ret ? ret : count;
> +}

returns a strange value on error.  Maybe we need to translate the "pcmcia
error code" to something more appropriate, or (preferably) make it return
a usual unix errno in the first place and translate _that_ to the "pcmcia
error code" in ds.c ?

Same comments for eject as well.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core



More information about the linux-pcmcia mailing list