mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	gpio: aggregator: Replace custom get_arg() with a generic next_arg()
cmdline library provides next_arg() helper to traverse over parameters and their values given in command line. Replace custom approach in the driver by it. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
This commit is contained in:
		
							parent
							
								
									65dd36a39d
								
							
						
					
					
						commit
						ac505b6f5f
					
				
					 1 changed files with 5 additions and 34 deletions
				
			
		| 
						 | 
					@ -37,31 +37,6 @@ struct gpio_aggregator {
 | 
				
			||||||
static DEFINE_MUTEX(gpio_aggregator_lock);	/* protects idr */
 | 
					static DEFINE_MUTEX(gpio_aggregator_lock);	/* protects idr */
 | 
				
			||||||
static DEFINE_IDR(gpio_aggregator_idr);
 | 
					static DEFINE_IDR(gpio_aggregator_idr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *get_arg(char **args)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	char *start, *end;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	start = skip_spaces(*args);
 | 
					 | 
				
			||||||
	if (!*start)
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (*start == '"') {
 | 
					 | 
				
			||||||
		/* Quoted arg */
 | 
					 | 
				
			||||||
		end = strchr(++start, '"');
 | 
					 | 
				
			||||||
		if (!end)
 | 
					 | 
				
			||||||
			return ERR_PTR(-EINVAL);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		/* Unquoted arg */
 | 
					 | 
				
			||||||
		for (end = start; *end && !isspace(*end); end++) ;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (*end)
 | 
					 | 
				
			||||||
		*end++ = '\0';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	*args = end;
 | 
					 | 
				
			||||||
	return start;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
 | 
					static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
 | 
				
			||||||
			 int hwnum, unsigned int *n)
 | 
								 int hwnum, unsigned int *n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -83,8 +58,8 @@ static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int aggr_parse(struct gpio_aggregator *aggr)
 | 
					static int aggr_parse(struct gpio_aggregator *aggr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						char *args = skip_spaces(aggr->args);
 | 
				
			||||||
	char *name, *offsets, *p;
 | 
						char *name, *offsets, *p;
 | 
				
			||||||
	char *args = aggr->args;
 | 
					 | 
				
			||||||
	unsigned long *bitmap;
 | 
						unsigned long *bitmap;
 | 
				
			||||||
	unsigned int i, n = 0;
 | 
						unsigned int i, n = 0;
 | 
				
			||||||
	int error = 0;
 | 
						int error = 0;
 | 
				
			||||||
| 
						 | 
					@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
 | 
				
			||||||
	if (!bitmap)
 | 
						if (!bitmap)
 | 
				
			||||||
		return -ENOMEM;
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (name = get_arg(&args), offsets = get_arg(&args); name;
 | 
						args = next_arg(args, &name, &p);
 | 
				
			||||||
	     offsets = get_arg(&args)) {
 | 
						while (*args) {
 | 
				
			||||||
		if (IS_ERR(name)) {
 | 
							args = next_arg(args, &offsets, &p);
 | 
				
			||||||
			pr_err("Cannot get GPIO specifier: %pe\n", name);
 | 
					 | 
				
			||||||
			error = PTR_ERR(name);
 | 
					 | 
				
			||||||
			goto free_bitmap;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		p = get_options(offsets, 0, &error);
 | 
							p = get_options(offsets, 0, &error);
 | 
				
			||||||
		if (error == 0 || *p) {
 | 
							if (error == 0 || *p) {
 | 
				
			||||||
| 
						 | 
					@ -125,7 +96,7 @@ static int aggr_parse(struct gpio_aggregator *aggr)
 | 
				
			||||||
				goto free_bitmap;
 | 
									goto free_bitmap;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		name = get_arg(&args);
 | 
							args = next_arg(args, &name, &p);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!n) {
 | 
						if (!n) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue