Re: [RFCv2 PATCH 2/4] bus: add Wiegand bus driver

From: Krzysztof Kozlowski
Date: Thu Oct 06 2022 - 04:30:05 EST


On 05/10/2022 16:57, Martin Zaťovič wrote:
> The Wiegand bus driver spawns devices and matches them with
> drivers.
>
> Signed-off-by: Martin Zaťovič <m.zatovic1@xxxxxxxxx>
> ---
> The bus driver currently assumes that any new Wiegand driver will
> have a matching entry in the devicetree. It is currently sufficient
> as I will only be implementing the GPIO driver. If someone
> implements a Wiegand driver that will not use devicetree, he will
> also have to edit this bus driver, in order to match properly. Is
> that a correct approach?

(...)

> +static struct wiegand_device *
> +of_register_wiegand_device(struct wiegand *wiegand, struct device_node *nc)
> +{
> + struct wiegand_device *dev;
> + const char *val;
> + int ret;
> +
> + dev = wiegand_alloc_device(wiegand);
> + if (!dev) {
> + dev_err(wiegand->dev,
> + "Wiegand device alloc error for %pOF\n", nc);
> + return ERR_PTR(-ENOMEM);
> + }
> +
> + ret = of_property_read_string(nc, "compatible", &val);
> + if (ret) {
> + dev_err(wiegand->dev, "%pOF has no valid 'compatible' property (%d)\n",
> + nc, ret);
> + goto err_put;
> + }
> +
> + if (strcmp(val, "wiegand,wiegand-gpio") == 0) {

This does not look right. Bus can have any device attached, so limiting
some bus behavior to a specific device is not really scalable.

Anyway device and node matching should not be with strcmp but rather
of_*_match().

Best regards,
Krzysztof