dmaengine: fix channel index enumeration
authorDave Jiang <dave.jiang@intel.com>
Mon, 13 Apr 2020 17:40:12 +0000 (10:40 -0700)
committerVinod Koul <vkoul@kernel.org>
Mon, 27 Apr 2020 15:56:23 +0000 (21:26 +0530)
commit0821009445a8261ac4d32a6df4b83938e007c765
treed59ad9425d0c1860538d3ce6173ab4ba2d570d49
parent0c89446379218698189a47871336cb30286a7197
dmaengine: fix channel index enumeration

When the channel register code was changed to allow hotplug operations,
dynamic indexing wasn't taken into account. When channels are randomly
plugged and unplugged out of order, the serial indexing breaks. Convert
channel indexing to using IDA tracking in order to allow dynamic
assignment. The previous code does not cause any regression bug for
existing channel allocation besides idxd driver since the hotplug usage
case is only used by idxd at this point.

With this change, the chan->idr_ref is also not needed any longer. We can
have a device with no channels registered due to hot plug. The channel
device release code no longer should attempt to free the dma device id on
the last channel release.

Fixes: e81274cd6b52 ("dmaengine: add support to dynamic register/unregister of channels")

Reported-by: Yixin Zhang <yixin.zhang@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Tested-by: Yixin Zhang <yixin.zhang@intel.com>
Link: https://lore.kernel.org/r/158679961260.7674.8485924270472851852.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/dmaengine.c
include/linux/dmaengine.h