2020-01-30 11:42:50

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 1/2] dmaengine: Cleanups for the slave <-> channel symlink support

No need to use goto to jump over the
return chan ? chan : ERR_PTR(-EPROBE_DEFER);
We can just revert the check and return right there.

Do not fail the channel request if the chan->name allocation fails, but
print a warning about it.

Change the dev_err to dev_warn if sysfs_create_link() fails as it is not
fatal.

Only attempt to remove the DMA_SLAVE_NAME symlink if it is created - or it
was attempted to be created.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/dma/dmaengine.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 7b1cefc3213a..75516f9fbab4 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -756,22 +756,24 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
}
mutex_unlock(&dma_list_mutex);

- if (!IS_ERR_OR_NULL(chan))
- goto found;
-
- return chan ? chan : ERR_PTR(-EPROBE_DEFER);
+ if (IS_ERR_OR_NULL(chan))
+ return chan ? chan : ERR_PTR(-EPROBE_DEFER);

found:
- chan->slave = dev;
chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
- if (!chan->name)
- return ERR_PTR(-ENOMEM);
+ if (!chan->name) {
+ dev_warn(dev,
+ "Cannot allocate memory for slave symlink name\n");
+ return chan;
+ }
+ chan->slave = dev;

if (sysfs_create_link(&chan->dev->device.kobj, &dev->kobj,
DMA_SLAVE_NAME))
- dev_err(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
+ dev_warn(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
if (sysfs_create_link(&dev->kobj, &chan->dev->device.kobj, chan->name))
- dev_err(dev, "Cannot create DMA %s symlink\n", chan->name);
+ dev_warn(dev, "Cannot create DMA %s symlink\n", chan->name);
+
return chan;
}
EXPORT_SYMBOL_GPL(dma_request_chan);
@@ -830,13 +832,14 @@ void dma_release_channel(struct dma_chan *chan)
/* drop PRIVATE cap enabled by __dma_request_channel() */
if (--chan->device->privatecnt == 0)
dma_cap_clear(DMA_PRIVATE, chan->device->cap_mask);
+
if (chan->slave) {
+ sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME);
sysfs_remove_link(&chan->slave->kobj, chan->name);
kfree(chan->name);
chan->name = NULL;
chan->slave = NULL;
}
- sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME);
mutex_unlock(&dma_list_mutex);
}
EXPORT_SYMBOL_GPL(dma_release_channel);
--
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


2020-01-30 15:23:01

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 1/2] dmaengine: Cleanups for the slave <-> channel symlink support

Hi Peter,

On Thu, Jan 30, 2020 at 12:41 PM Peter Ujfalusi <[email protected]> wrote:
> No need to use goto to jump over the
> return chan ? chan : ERR_PTR(-EPROBE_DEFER);
> We can just revert the check and return right there.
>
> Do not fail the channel request if the chan->name allocation fails, but
> print a warning about it.
>
> Change the dev_err to dev_warn if sysfs_create_link() fails as it is not
> fatal.
>
> Only attempt to remove the DMA_SLAVE_NAME symlink if it is created - or it
> was attempted to be created.
>
> Signed-off-by: Peter Ujfalusi <[email protected]>

Thanks for your patch!

> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -756,22 +756,24 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
> }
> mutex_unlock(&dma_list_mutex);
>
> - if (!IS_ERR_OR_NULL(chan))
> - goto found;
> -
> - return chan ? chan : ERR_PTR(-EPROBE_DEFER);
> + if (IS_ERR_OR_NULL(chan))
> + return chan ? chan : ERR_PTR(-EPROBE_DEFER);
>
> found:
> - chan->slave = dev;
> chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
> - if (!chan->name)
> - return ERR_PTR(-ENOMEM);
> + if (!chan->name) {
> + dev_warn(dev,
> + "Cannot allocate memory for slave symlink name\n");

No need to print a message, as the memory allocator core will have
screamed already.

> + return chan;
> + }
> + chan->slave = dev;
>
> if (sysfs_create_link(&chan->dev->device.kobj, &dev->kobj,
> DMA_SLAVE_NAME))
> - dev_err(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
> + dev_warn(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
> if (sysfs_create_link(&dev->kobj, &chan->dev->device.kobj, chan->name))
> - dev_err(dev, "Cannot create DMA %s symlink\n", chan->name);
> + dev_warn(dev, "Cannot create DMA %s symlink\n", chan->name);
> +
> return chan;
> }
> EXPORT_SYMBOL_GPL(dma_request_chan);

With the above fixed:
Reviewed-by: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2020-01-31 07:15:57

by Peter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH 1/2] dmaengine: Cleanups for the slave <-> channel symlink support

Hi Geert,

On 30/01/2020 17.20, Geert Uytterhoeven wrote:
> Hi Peter,
>
> On Thu, Jan 30, 2020 at 12:41 PM Peter Ujfalusi <[email protected]> wrote:
>> No need to use goto to jump over the
>> return chan ? chan : ERR_PTR(-EPROBE_DEFER);
>> We can just revert the check and return right there.
>>
>> Do not fail the channel request if the chan->name allocation fails, but
>> print a warning about it.
>>
>> Change the dev_err to dev_warn if sysfs_create_link() fails as it is not
>> fatal.
>>
>> Only attempt to remove the DMA_SLAVE_NAME symlink if it is created - or it
>> was attempted to be created.
>>
>> Signed-off-by: Peter Ujfalusi <[email protected]>
>
> Thanks for your patch!
>
>> --- a/drivers/dma/dmaengine.c
>> +++ b/drivers/dma/dmaengine.c
>> @@ -756,22 +756,24 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
>> }
>> mutex_unlock(&dma_list_mutex);
>>
>> - if (!IS_ERR_OR_NULL(chan))
>> - goto found;
>> -
>> - return chan ? chan : ERR_PTR(-EPROBE_DEFER);
>> + if (IS_ERR_OR_NULL(chan))
>> + return chan ? chan : ERR_PTR(-EPROBE_DEFER);
>>
>> found:
>> - chan->slave = dev;
>> chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
>> - if (!chan->name)
>> - return ERR_PTR(-ENOMEM);
>> + if (!chan->name) {
>> + dev_warn(dev,
>> + "Cannot allocate memory for slave symlink name\n");
>
> No need to print a message, as the memory allocator core will have
> screamed already.

Right, I tend to forget this ;)

>
>> + return chan;
>> + }
>> + chan->slave = dev;
>>
>> if (sysfs_create_link(&chan->dev->device.kobj, &dev->kobj,
>> DMA_SLAVE_NAME))
>> - dev_err(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
>> + dev_warn(dev, "Cannot create DMA %s symlink\n", DMA_SLAVE_NAME);
>> if (sysfs_create_link(&dev->kobj, &chan->dev->device.kobj, chan->name))
>> - dev_err(dev, "Cannot create DMA %s symlink\n", chan->name);
>> + dev_warn(dev, "Cannot create DMA %s symlink\n", chan->name);
>> +
>> return chan;
>> }
>> EXPORT_SYMBOL_GPL(dma_request_chan);
>
> With the above fixed:
> Reviewed-by: Geert Uytterhoeven <[email protected]>

Thanks,
- Péter

>
> Gr{oetje,eeting}s,
>
> Geert
>

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki