Re: [PATCH 10/11] EDAC/ghes: Create an own device for each mci

From: Borislav Petkov
Date: Mon Mar 16 2020 - 05:45:21 EST


On Fri, Mar 06, 2020 at 04:13:17PM +0100, Robert Richter wrote:
> Each edac mc must have a unique device for identification (see
> add_mc_to_global_list()). This 1:1 mapping between parent device and
> mci is a limitation for supporting multiple instances created by the
> ghes driver. Solve this by creating an own device in between of the
> ghes parent and the mci struct, this allows a 1:n mapping between
> both.
>
> Implement this using a platform device as this is the least possible
> effort to create and free a device. It shows up nicely in sysfs:
>
> # find /sys/ -name ghes_mc*
> /sys/devices/platform/GHES.0/ghes_mc.1
> /sys/devices/platform/GHES.0/ghes_mc.0
> /sys/bus/platform/devices/ghes_mc.1
> /sys/bus/platform/devices/ghes_mc.0
>
> Signed-off-by: Robert Richter <rrichter@xxxxxxxxxxx>
> ---
> drivers/edac/ghes_edac.c | 26 +++++++++++++++++++++++---
> 1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
> index cd61b8ae49f6..64220397296e 100644
> --- a/drivers/edac/ghes_edac.c
> +++ b/drivers/edac/ghes_edac.c
> @@ -539,6 +539,8 @@ static struct acpi_platform_list plat_list[] = {
> static struct mem_ctl_info *ghes_mc_create(struct device *dev, int mc_idx,
> int num_dimm)
> {
> + struct platform_device_info pdevinfo;
> + struct platform_device *pdev;
> struct edac_mc_layer layers[1];
> struct mem_ctl_info *mci;
> struct ghes_mci *pvt;
> @@ -547,13 +549,23 @@ static struct mem_ctl_info *ghes_mc_create(struct device *dev, int mc_idx,
> layers[0].size = num_dimm;
> layers[0].is_virt_csrow = true;
>
> + pdevinfo = (struct platform_device_info){
> + .parent = dev,
> + .name = "ghes_mc",
> + .id = mc_idx,
> + };

You can statically allocate that one once at the top of the file and
assign ->parent and ->id each time before calling the function below.

> +
> + pdev = platform_device_register_full(&pdevinfo);
> + if (IS_ERR(pdev))
> + goto fail;
> +

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette