Re: [RESEND][PATCH] early platform drivers V2

From: roel kluin
Date: Thu Jan 15 2009 - 05:30:16 EST


> +static int __init early_platform_match(struct early_platform_driver *epdrv,
> + struct platform_device **pdevs,
> + int nr_pdevs, int id,
> + struct platform_device **match)
> +{
> + struct platform_device *pdev;
> + int k, n, match_id;
> +
> + if (id == -2)
> + match_id = epdrv->requested_id;
> + else
> + match_id = id;
> +
> + n = 0;
> + *match = NULL;
> + for (k = 0; k < nr_pdevs; k++) {
> + pdev = pdevs[k];
> + if (platform_match(&pdev->dev, &epdrv->pdrv->driver)) {

> + if (id != -2) /* skip previously checked device */
> + if (match_id == epdrv->requested_id)
> + goto skip;
> +
> + if (pdev->id == match_id)
> + *match = pdev;
> +
> +skip:
> + if (pdev->id > match_id)
> + n++;

you can replace the 10 lines above by:

/* skip previously checked device */
if ((id == -2 || match_id != epdrv->requested_id) && pdev->id == match_id)
*match = pdev;
else if (pdev->id > match_id)
n++;

> + }
> + }
> +
> + return n;
> +}

> +/**
> + * early_platform_driver_probe
> + * @class_str: string to identify early platform driver class
> + * @pdevs: platform devices to match against
> + * @nr_pdevs: number of platform devices to match against
> + * @nr_probe: number of platform devices to successfully probe before exiting
> + */
> +int __init early_platform_driver_probe(char *class_str,
> + struct platform_device **pdevs,
> + int nr_pdevs, int nr_probe)
> +{
> + struct early_platform_driver *epdrv;
> + struct platform_device *match;
> + int k, n, i;
> +
> + /* The "class_str" parameter may or may not be present on the kernel
> + * command line. If it is present then there may be more than one
> + * matching parameter.
> + *
> + * Since we register our early platform drivers using early_param()
> + * we need to make sure that they also get registered in the case
> + * when the parameter is missing from the kernel command line.
> + *
> + * We use parse_early_options() to make sure the early_param() gets
> + * called at least once. The early_param() may be called more than
> + * once since the name of the preferred device may be specified on
> + * the kernel command line. early_platform_driver_register() handles
> + * this case for us.
> + */
> + parse_early_options(class_str);
> +
> + n = 0;
> + list_for_each_entry(epdrv, &early_platform_driver_list, list) {
> + /* only use drivers matching our class_str */
> + if (strcmp(class_str, epdrv->class_str))
> + continue;
> +
> + /* start with exact device match, continue with any device */
> + k = 1;
> + for (i = -2; k && n < nr_probe; i++) {
> + k = early_platform_match(epdrv, pdevs, nr_pdevs,
> + i, &match);
> + if (!match)
> + continue;
> +
> + if (epdrv->pdrv->probe(match)) {

shouldn't this be

if (!epdrv->pdrv->probe(match)) {

> + pr_warning("%s: unable to probe %s early.\n",
> + class_str, match->name);
> + continue;
> + }
> + n++;
> + }
> + }
> +
> + if (!n)
> + pr_warning("%s: no early platform devices found.\n", class_str);
> +
> + return n;
> +}

I think k, n and i could get more descriptive names
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/