mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* gpiolib: Questions about gpiochip_find_base()
@ 2010-11-09 13:04 Simon Horman
  0 siblings, 0 replies; only message in thread
From: Simon Horman @ 2010-11-09 13:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Anton Vorontsov, David Brownell

Hi,

I have a few questions about gpiochip_find_base() which I hope someone can
help with.

* At the end of gpiochip_add() there is the following code:

	if (gpio_is_valid(base))
		pr_debug("%s: found new base at %d\n", __func__, base);
	return base;

  It is unclear to me why !gpio_is_valid(base) isn't an error condition
  given that the following appears in gpiochip_add(), the caller of
  gpiochip_find_base(), in the case where base isn't to be dynamic
  selected.

	if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))
			&& base >= 0) {
		status = -EINVAL;
		goto fail;
	}

* In the same vein, its unclear to me why
  the loop in gpiochip_find_base() checks values of i
  that may not be valid according to gpio_is_valid().

  Specifically I am wondering why

	for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) {
		...
		if (!chip && !test_bit(FLAG_RESERVED, &desc->flags)) {
			...

  isn't something like


	for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) {
		...
		if (gpio_is_valid(i) && !chip &&
		    !test_bit(FLAG_RESERVED, &desc->flags)) {
			...

* I am wondering if in gpiochip_add() the following is unnecessary
  in the case where base is dynamic as gpiochip_add() seems to
  ensure that gpio_desc[id].chip is NULL for the dynamically selected range.

	for (id = base; id < base + chip->ngpio; id++) {
		if (gpio_desc[id].chip != NULL) {
			status = -EBUSY;
			break;
		}
	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-11-09 13:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-09 13:04 gpiolib: Questions about gpiochip_find_base() Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®