RE: [PATCH v2] platform/mellanox: Add some null/error pointer checks to mlxbf-pmc.c

From: Ilpo Järvinen
Date: Mon Dec 04 2023 - 08:07:46 EST


> > Subject: [PATCH v2] platform/mellanox: Add some null/error pointer checks to
> > mlxbf-pmc.c
> >
> > devm_kasprintf() returns a pointer to dynamically allocated memory which
> > can be NULL upon failure.
> > devm_hwmon_device_register_with_groups return a error pointer upon
> > failure.
> >
> > Compile-tested only.
> >
> > Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox
> > BlueField PMC driver")
> > Suggested-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
> > Suggested-by: Vadim Pasternak <vadimp@xxxxxxxxxx>
> > Signed-off-by: Kunwu Chan <chentao@xxxxxxxxxx>
>
> Reviewed-by: Vadim Pasternak <vadimp@xxxxxxxxxx>

> > attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
> > "enable");
> > + if (!attr->dev_attr.attr.name)
> > + return -ENOMEM;

> > pmc->hwmon_dev = devm_hwmon_device_register_with_groups(
> > dev, "bfperf", pmc, pmc->groups);
> > + if (IS_ERR(pmc->hwmon_dev))
> > + return PTR_ERR(pmc->hwmon_dev);

Thank you both, applied to review-ilpo and will go into fixes branch once
LKP has had its chance to build this.

In the end, I decided to split the devm_kasprintf() and
devm_hwmon_device_register_with_groups() changes into separate commits.

--
i.