[PATCH 2/4] gpiolib: add bitmask for valid GPIO lines

Timur Tabi timur at codeaurora.org
Tue Oct 31 11:54:56 PDT 2017


On 10/31/2017 04:12 AM, Andy Shevchenko wrote:
> Instead of mangling this function wouldn't be better to introduce a
> separate one for line and perhaps a third one which calls them both?

The diff is convoluted, but the end result is clean:

static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip)
{
	if (gpiochip->irq_need_valid_mask) {
		gpiochip->irq_valid_mask =
			kcalloc(BITS_TO_LONGS(gpiochip->ngpio),
				sizeof(long), GFP_KERNEL);
		if (!gpiochip->irq_valid_mask)
			return -ENOMEM;

		/* Assume by default all GPIOs are valid */
		bitmap_fill(gpiochip->irq_valid_mask, gpiochip->ngpio);
	}

	if (gpiochip->line_need_valid_mask) {
		gpiochip->line_valid_mask =
			kcalloc(BITS_TO_LONGS(gpiochip->ngpio),
				sizeof(long), GFP_KERNEL);
		if (!gpiochip->line_valid_mask)
			return -ENOMEM;

		/* Assume by default all GPIOs are valid */
		bitmap_fill(gpiochip->line_valid_mask, gpiochip->ngpio);
	}

	return 0;
}

Is this acceptable?

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.



More information about the linux-arm-kernel mailing list