Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm: unbalanced of_node_put() in mipi_dbi_device_release()
- [Low] drm: mismatched Return kernel-doc in drm_mipi_dbi_bus.c
--

commit 3fe40d87109b802b6b8c4ac15ef288e1fecb74a0
Author: Svyatoslav Ryhel <[email protected]>

drm: Add MIPI DBI bus support for MIPI DBI Type A and B

This commit introduces a MIPI DBI bus and driver model infrastructure to
support MIPI DBI Type A and Type B hosts and peripheral devices.

> diff --git a/drivers/gpu/drm/drm_mipi_dbi_bus.c 
> b/drivers/gpu/drm/drm_mipi_dbi_bus.c
> new file mode 100644
> index 0000000000000..fa8cd748d7b3c
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_mipi_dbi_bus.c

[ ... ]

> +static void mipi_dbi_device_release(struct device *dev)
> +{
> +     of_node_put(dev->of_node);
> +     kfree(to_mipi_dbi_device(dev));
> +}
> +
> +static void mipi_dbi_device_unregister(void *data)
> +{
> +     struct device *dev = data;
> +
> +     of_node_clear_flag(dev->of_node, OF_POPULATED);
> +     device_unregister(dev);
> +}
> +
> +/**
> + * devm_mipi_dbi_device_register() - create a managed peripheral MIPI DBI
> + *                                Type A or B device.
> + * @dev: device to tie the MIPI-DBI device lifetime to
> + * @host: DBI host to which this device is connected
> + * @np: device tree node associated with the panel MIPI DBI device
> + *
> + * This function is called by DBI host driver to create panel device.
> + * It automatically calls mipi_dbi_device_unregister() when @dev is
> + * unbound. It does not automatically free passed device node pointer,
> + * it must be put manually.
> + *
> + * Returns:
> + * A pointer to the newly created MIPI DBI device, or, a pointer encoded
> + * with an error.
> + */
> +struct mipi_dbi_device *
> +devm_mipi_dbi_device_register(struct device *dev, struct mipi_dbi_host *host,
> +                           struct device_node *np)
> +{
> +     struct mipi_dbi_device *dbidev;
> +     int ret;
> +
> +     if (!host || !host->dev || !host->dbi || !host->dbi->command ||
> +         !host->ops || !host->ops->attach || !host->ops->detach || !np)
> +             return ERR_PTR(-EINVAL);
> +
> +     if (!of_device_is_available(np))
> +             return ERR_PTR(-ENODEV);
> +
> +     dbidev = kzalloc_obj(*dbidev);
> +     if (!dbidev)
> +             return ERR_PTR(-ENOMEM);
> +
> +     if (of_node_test_and_set_flag(np, OF_POPULATED)) {
> +             kfree(dbidev);
> +             return ERR_PTR(-EBUSY);
> +     }
> +
> +     dbidev->host = host;
> +     dbidev->dbi = host->dbi;
> +     device_initialize(&dbidev->dev);
> +     dbidev->dev.parent = host->dev;
> +     dbidev->dev.bus = &mipi_dbi_bus_type;
> +     dbidev->dev.release = mipi_dbi_device_release;
> +     device_set_node(&dbidev->dev, of_fwnode_handle(np));
> +
> +     ret = dev_set_name(&dbidev->dev, "%s:%s", dev_name(host->dev), 
> np->full_name);
> +     if (ret)
> +             goto put_device;
> +
> +     ret = device_add(&dbidev->dev);
> +     if (ret)
> +             goto put_device;
> +
> +     ret = devm_add_action_or_reset(dev, mipi_dbi_device_unregister,
> +                                    &dbidev->dev);
> +     if (ret)
> +             return ERR_PTR(ret);
> +
> +     return dbidev;
> +
> +put_device:
> +     of_node_clear_flag(np, OF_POPULATED);
> +     put_device(&dbidev->dev);
> +     return ERR_PTR(ret);
> +}

[Severity: High]
Does mipi_dbi_device_release() drop a reference on dev->of_node that
devm_mipi_dbi_device_register() never acquired?

device_set_node(&dbidev->dev, of_fwnode_handle(np)) does not call
of_node_get(np), and callers are documented as still owning their reference
to np.  When put_device() runs on error unwind or when
mipi_dbi_device_unregister() later unregisters the device,
mipi_dbi_device_release() calls of_node_put(dev->of_node) and underflows the
device_node refcount.  Should devm_mipi_dbi_device_register() call
of_node_get(np) when associating np with dbidev->dev?

[ ... ]

> +/**
> + * devm_mipi_dbi_attach() - managed attach of peripheral DBI device to its 
> MIPI
> + *                       DBI Type A or B devices.
> + * @dev: device to tie the MIPI-DBI device lifetime to
> + * @dbidev: DBI peripheral
> + */
> +int devm_mipi_dbi_attach(struct device *dev, struct mipi_dbi_device *dbidev)

[ ... ]

> +/**
> + * mipi_dbi_driver_unregister() - unregister a driver for MIPI DBI Type A or 
> B devices.
> + * @drv: DBI driver structure
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +void mipi_dbi_driver_unregister(struct mipi_dbi_driver *drv)

[ ... ]

> diff --git a/include/drm/drm_mipi_dbi_bus.h b/include/drm/drm_mipi_dbi_bus.h
> new file mode 100644
> index 0000000000000..886f175a80cb9
> --- /dev/null
> +++ b/include/drm/drm_mipi_dbi_bus.h

[ ... ]

> +/**
> + * struct mipi_dbi_device - DBI peripheral device for MIPI DBI Type A and B.
> + *                       This structure describes a peripheral DBI device,
> + *                       an endpoint for DSC commands and video data, and 
> must
> + *                       be paired with a DBI host device for MIPI DBI Type A
> + *                       and B. This layout is built to closely resemble
> + *                       the DSI framework.
> + *
> + *                       If your device is MIPI DBI Type C (with an SPI
> + *                       control bus) and incorporates DBI within, you
> + *                       should use the mipi_dbi_dev structure and Type C
> + *                       framework from drm_mipi_dbi.c.
> + * @dev: driver model device node for this peripheral
> + * @dbi: MIPI DBI interface
> + * @host: DBI host for this peripheral
> + * @attached: the DBI device has been successfully attached
> + */
> +struct mipi_dbi_device {

[Severity: Low]
This isn't a bug, but the Return: kernel-doc line on
mipi_dbi_driver_unregister() (which returns void) looks like it belongs on
devm_mipi_dbi_attach(), which returns int and has no Return: section.  Also,
in struct mipi_dbi_device, the extended description paragraphs appear before
the @member entries without a blank comment line after the one-line summary.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to