lkml.org 
[lkml]   [2021]   [Dec]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v3 18/23] counter: ftm-quaddec: Convert to new counter registration
    Date
    This fixes device lifetime issues where it was possible to free a live
    struct device.

    Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")
    Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    ---
    drivers/counter/ftm-quaddec.c | 26 +++++++++++++-------------
    1 file changed, 13 insertions(+), 13 deletions(-)

    diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
    index f5d92df6a611..2a58582a9df4 100644
    --- a/drivers/counter/ftm-quaddec.c
    +++ b/drivers/counter/ftm-quaddec.c
    @@ -26,7 +26,6 @@
    })

    struct ftm_quaddec {
    - struct counter_device counter;
    struct platform_device *pdev;
    void __iomem *ftm_base;
    bool big_endian;
    @@ -259,15 +258,17 @@ static struct counter_count ftm_quaddec_counts = {

    static int ftm_quaddec_probe(struct platform_device *pdev)
    {
    + struct counter_device *counter;
    struct ftm_quaddec *ftm;

    struct device_node *node = pdev->dev.of_node;
    struct resource *io;
    int ret;

    - ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
    - if (!ftm)
    + counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
    + if (!counter)
    return -ENOMEM;
    + ftm = counter_priv(counter);

    io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    if (!io) {
    @@ -283,14 +284,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
    dev_err(&pdev->dev, "Failed to map memory region\n");
    return -EINVAL;
    }
    - ftm->counter.name = dev_name(&pdev->dev);
    - ftm->counter.parent = &pdev->dev;
    - ftm->counter.ops = &ftm_quaddec_cnt_ops;
    - ftm->counter.counts = &ftm_quaddec_counts;
    - ftm->counter.num_counts = 1;
    - ftm->counter.signals = ftm_quaddec_signals;
    - ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
    - ftm->counter.priv = ftm;
    + counter->name = dev_name(&pdev->dev);
    + counter->parent = &pdev->dev;
    + counter->ops = &ftm_quaddec_cnt_ops;
    + counter->counts = &ftm_quaddec_counts;
    + counter->num_counts = 1;
    + counter->signals = ftm_quaddec_signals;
    + counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);

    mutex_init(&ftm->ftm_quaddec_mutex);

    @@ -300,9 +300,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
    if (ret)
    return ret;

    - ret = devm_counter_register(&pdev->dev, &ftm->counter);
    + ret = devm_counter_add(&pdev->dev, counter);
    if (ret)
    - return ret;
    + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");

    return 0;
    }
    --
    2.34.1
    \
     
     \ /
      Last update: 2021-12-29 16:45    [W:3.429 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site