提交 7f92408c 编写于 作者: N Nikita Yushchenko 提交者: Zheng Zengkai

staging: most: dim2: use device release method

stable inclusion
from stable-v5.10.87
commit 9099f3512678596de7200bf748294b5e757d9a63
bugzilla: 186049 https://gitee.com/openeuler/kernel/issues/I4QVYL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9099f3512678596de7200bf748294b5e757d9a63

--------------------------------

commit d445aa40 upstream.

Commit 723de0f9 ("staging: most: remove device from interface
structure") moved registration of driver-provided struct device to
the most subsystem. This updated dim2 driver as well.

However, struct device passed to register_device() becomes refcounted,
and must not be explicitly deallocated, but must provide release method
instead. Which is incompatible with managing it via devres.

This patch makes the device structure allocated without devres, adds
device release method, and moves device destruction there.

Fixes: 723de0f9 ("staging: most: remove device from interface structure")
Signed-off-by: NNikita Yushchenko <nikita.yoush@cogentembedded.com>
Link: https://lore.kernel.org/r/20211005143448.8660-2-nikita.yoush@cogentembedded.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 d74c337c
......@@ -723,6 +723,23 @@ static int get_dim2_clk_speed(const char *clock_speed, u8 *val)
return -EINVAL;
}
static void dim2_release(struct device *d)
{
struct dim2_hdm *dev = container_of(d, struct dim2_hdm, dev);
unsigned long flags;
kthread_stop(dev->netinfo_task);
spin_lock_irqsave(&dim_lock, flags);
dim_shutdown();
spin_unlock_irqrestore(&dim_lock, flags);
if (dev->disable_platform)
dev->disable_platform(to_platform_device(d->parent));
kfree(dev);
}
/*
* dim2_probe - dim2 probe handler
* @pdev: platform device structure
......@@ -743,7 +760,7 @@ static int dim2_probe(struct platform_device *pdev)
enum { MLB_INT_IDX, AHB0_INT_IDX };
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
......@@ -755,25 +772,27 @@ static int dim2_probe(struct platform_device *pdev)
"microchip,clock-speed", &clock_speed);
if (ret) {
dev_err(&pdev->dev, "missing dt property clock-speed\n");
return ret;
goto err_free_dev;
}
ret = get_dim2_clk_speed(clock_speed, &dev->clk_speed);
if (ret) {
dev_err(&pdev->dev, "bad dt property clock-speed\n");
return ret;
goto err_free_dev;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dev->io_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(dev->io_base))
return PTR_ERR(dev->io_base);
if (IS_ERR(dev->io_base)) {
ret = PTR_ERR(dev->io_base);
goto err_free_dev;
}
of_id = of_match_node(dim2_of_match, pdev->dev.of_node);
pdata = of_id->data;
ret = pdata && pdata->enable ? pdata->enable(pdev) : 0;
if (ret)
return ret;
goto err_free_dev;
dev->disable_platform = pdata ? pdata->disable : NULL;
......@@ -864,24 +883,19 @@ static int dim2_probe(struct platform_device *pdev)
dev->most_iface.request_netinfo = request_netinfo;
dev->most_iface.driver_dev = &pdev->dev;
dev->most_iface.dev = &dev->dev;
dev->dev.init_name = "dim2_state";
dev->dev.init_name = dev->name;
dev->dev.parent = &pdev->dev;
dev->dev.release = dim2_release;
ret = most_register_interface(&dev->most_iface);
if (ret) {
dev_err(&pdev->dev, "failed to register MOST interface\n");
goto err_stop_thread;
}
return 0;
return most_register_interface(&dev->most_iface);
err_stop_thread:
kthread_stop(dev->netinfo_task);
err_shutdown_dim:
dim_shutdown();
err_disable_platform:
if (dev->disable_platform)
dev->disable_platform(pdev);
err_free_dev:
kfree(dev);
return ret;
}
......@@ -895,17 +909,8 @@ static int dim2_probe(struct platform_device *pdev)
static int dim2_remove(struct platform_device *pdev)
{
struct dim2_hdm *dev = platform_get_drvdata(pdev);
unsigned long flags;
most_deregister_interface(&dev->most_iface);
kthread_stop(dev->netinfo_task);
spin_lock_irqsave(&dim_lock, flags);
dim_shutdown();
spin_unlock_irqrestore(&dim_lock, flags);
if (dev->disable_platform)
dev->disable_platform(pdev);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册