All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
	Vinod Koul <vkoul@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	dmaengine@vger.kernel.org,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] dmaengine: Create symlinks between DMA channels and slaves
Date: Thu, 30 Jan 2020 10:51:26 +0100	[thread overview]
Message-ID: <CAMuHMdWim4kq=JCrprybMOA+ipaxNTm4+zgjrmoFxffM+nSnPw@mail.gmail.com> (raw)
In-Reply-To: <e219bc58-0d30-582f-4872-559097f212d2@ti.com>

Hi Peter,

On Thu, Jan 30, 2020 at 10:42 AM Peter Ujfalusi <peter.ujfalusi@ti.com> wrote:
> On 17/01/2020 17.30, Geert Uytterhoeven wrote:
> > Currently it is not easy to find out which DMA channels are in use, and
> > which slave devices are using which channels.
> >
> > Fix this by creating two symlinks between the DMA channel and the actual
> > slave device when a channel is requested:
> >   1. A "slave" symlink from DMA channel to slave device,
> >   2. A "dma:<name>" symlink slave device to DMA channel.
> > When the channel is released, the symlinks are removed again.
> > The latter requires keeping track of the slave device and the channel
> > name in the dma_chan structure.
> >
> > Note that this is limited to channel request functions for requesting an
> > exclusive slave channel that take a device pointer (dma_request_chan()
> > and dma_request_slave_channel*()).
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

> > --- a/drivers/dma/dmaengine.c
> > +++ b/drivers/dma/dmaengine.c
> > @@ -60,6 +60,8 @@ static long dmaengine_ref_count;
> >
> >  /* --- sysfs implementation --- */
> >
> > +#define DMA_SLAVE_NAME       "slave"
> > +
> >  /**
> >   * dev_to_dma_chan - convert a device pointer to its sysfs container object
> >   * @dev - device node
> > @@ -730,11 +732,11 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
> >       if (has_acpi_companion(dev) && !chan)
> >               chan = acpi_dma_request_slave_chan_by_name(dev, name);
> >
> > -     if (chan) {
> > -             /* Valid channel found or requester needs to be deferred */
> > -             if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
> > -                     return chan;
> > -     }
> > +     if (PTR_ERR(chan) == -EPROBE_DEFER)
> > +             return chan;
> > +
> > +     if (!IS_ERR_OR_NULL(chan))
> > +             goto found;
> >
> >       /* Try to find the channel via the DMA filter map(s) */
> >       mutex_lock(&dma_list_mutex);
> > @@ -754,7 +756,23 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
> >       }
> >       mutex_unlock(&dma_list_mutex);
> >
> > -     return chan ? chan : ERR_PTR(-EPROBE_DEFER);
> > +     if (!IS_ERR_OR_NULL(chan))
> > +             goto found;
> > +
> > +     return ERR_PTR(-EPROBE_DEFER);
> > +
> > +found:
> > +     chan->slave = dev;
> > +     chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
> > +     if (!chan->name)
> > +             return ERR_PTR(-ENOMEM);
>
> You will lock the channel... It is requested, but it is not released in
> case of failure.

True. Perhaps this error should just be ignored, cfr. below.
However, if this operation fails, chances are high the system will die very soon
anyway.

> > +
> > +     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);
> > +     if (sysfs_create_link(&dev->kobj, &chan->dev->device.kobj, chan->name))
> > +             dev_err(dev, "Cannot create DMA %s symlink\n", chan->name);
>
> It is not a problem if these fail?

IMHO, a failure to create these links is not fatal for the operation of
the device, and thus can be ignored.  Just like for debugfs.

> > +     return chan;
> >  }
> >  EXPORT_SYMBOL_GPL(dma_request_chan);
> >
> > @@ -812,6 +830,13 @@ 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->slave->kobj, chan->name);
> > +             kfree(chan->name);
> > +             chan->name = NULL;
> > +             chan->slave = NULL;
> > +     }
> > +     sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME);
>
> If a non slave channel is released, then you remove the link you have
> never created?
>
> What happens if the link creation fails and here you attempt to remove
> the failed ones?

sysfs_remove_link() should handle removing non-existent links, and just
return -ENOENT.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

  reply	other threads:[~2020-01-30  9:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17 15:30 [PATCH v2] dmaengine: Create symlinks between DMA channels and slaves Geert Uytterhoeven
2020-01-17 16:26 ` Niklas Söderlund
2020-01-17 20:10 ` Peter Ujfalusi
2020-01-20  9:01   ` Geert Uytterhoeven
2020-01-20 10:16     ` Peter Ujfalusi
2020-01-20 10:51       ` Geert Uytterhoeven
2020-01-20 12:06         ` Peter Ujfalusi
2020-01-21 20:22           ` Geert Uytterhoeven
2020-01-22  9:40             ` Vinod Koul
2020-01-24  6:13               ` Vinod Koul
2020-01-24  7:31                 ` Peter Ujfalusi
2020-01-27  5:08                   ` Vinod Koul
     [not found] ` <CGME20200129174723eucas1p1fe4f76325f463fc9e3645ce18740d2eb@eucas1p1.samsung.com>
2020-01-29 17:47   ` Marek Szyprowski
2020-01-30  8:30     ` Geert Uytterhoeven
2020-01-30 10:33       ` Marek Szyprowski
2020-01-30 10:47         ` Geert Uytterhoeven
2020-01-30  9:43 ` Peter Ujfalusi
2020-01-30  9:51   ` Geert Uytterhoeven [this message]
2020-01-30 10:22     ` Peter Ujfalusi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMuHMdWim4kq=JCrprybMOA+ipaxNTm4+zgjrmoFxffM+nSnPw@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.