lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <90049936.xgdXKqK565@wuerfel>
Date:	Mon, 04 May 2015 20:46:13 +0200
From:	Arnd Bergmann <arnd@...db.de>
To:	Joachim Eastwood <manabian@...il.com>
Cc:	linux-arm-kernel@...ts.infradead.org, peppe.cavallaro@...com,
	netdev@...r.kernel.org, davem@...emloft.net
Subject: Re: [PATCH 1/2] stmac: add dwmac glue for NXP 18xx/43xx family

On Monday 04 May 2015 00:14:11 Joachim Eastwood wrote:
=> >It should be fairly straightforward to split the probe function
> >into two and export a function that takes a device and a stmmac_of_data
> >pointer as arguments, and declare a module_platform_driver in your
> >code.
> 
> How about something like the patch below. All it does is to play a
> little trick with the of_match_device in the dt config function and
> export the probe/remove/pm stuff for the driver.
> 
> The dwmac-lpc18xx would then become something like this:
> 
> static const struct stmmac_of_data lpc18xx_dwmac_data = {
> 	.has_gmac = 1,
> 	.setup = lpc18xx_dwmac_setup,
> 	.init = lpc18xx_dwmac_init,
> };
> 
> static const struct of_device_id lpc18xx_dwmac_match[] = {
> 	{ .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
> 	{ }
> };
> MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
> 
> static struct platform_driver lpc18xx_dwmac_driver = {
> 	.probe  = stmmac_pltfr_probe,
> 	.remove = stmmac_pltfr_remove,
> 	.driver = {
> 		.name           = "lpc18xx-dwmac",
> 		.pm             = &stmmac_pltfr_pm_ops,
> 		.of_match_table = lpc18xx_dwmac_match,
> 	},
> };
> module_platform_driver(lpc18xx_dwmac_driver);
> 
> All though this seem to work, stmmac_platform.c could benefit from
> some refactoring. But this patch and then fixing the other DT users
> could be a first step.

Sounds good, yes.

> -	device = of_match_device(stmmac_dt_ids, &pdev->dev);
> +	device = of_match_device(dev->driver->of_match_table, dev);
>  	if (!device)
>  		return -ENODEV;

Ah, that is a nice trick to avoid passing the various match tables
from a lot of duplicated probe functions.

I wonder if we could generalize that for use by any driver and
introduce a common helper

void *of_platform_match_data(struct device *dev)
{
	struct of_device_id *id;

	if (!dev || !dev->of_node)
		return NULL;

	id = of_match_device(dev->driver->of_match_table, dev);
	if (!id)
		return NULL;

	return id->data;
}
EXPORT_SYMBOL_GPL(of_platform_match_data);

I think that could save a few lines from many drivers, and it had not
occurred to me that we can take this shortcut.

The rest of your patch also looks great to me.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ