[bug report] dmaengine: break out channel registration
From: Dan Carpenter <hidden>
Date: 2020-01-31 05:00:48
Hello Dave Jiang,
The patch d2fb0a043838: "dmaengine: break out channel registration"
from Jan 21, 2020, leads to the following static checker warning:
drivers/dma/dmaengine.c:965 __dma_async_device_channel_register()
error: potential NULL dereference 'tchan'.
drivers/dma/dmaengine.c
954 static int __dma_async_device_channel_register(struct dma_device *device,
955 struct dma_chan *chan,
956 int chan_id)
957 {
958 int rc = 0;
959 int chancnt = device->chancnt;
960 atomic_t *idr_ref;
961 struct dma_chan *tchan;
962
963 tchan = list_first_entry_or_null(&device->channels,
^^^^^^^^
The "or_null" suggests that "tchan" can be NULL
964 struct dma_chan, device_node);
965 if (tchan->dev) {
^^^^^^^^^^
so this should be "if (tchan && tchan->dev)"?
966 idr_ref = tchan->dev->idr_ref;
967 } else {
968 idr_ref = kmalloc(sizeof(*idr_ref), GFP_KERNEL);
969 if (!idr_ref)
970 return -ENOMEM;
971 atomic_set(idr_ref, 0);
972 }
973
974 chan->local = alloc_percpu(typeof(*chan->local));
975 if (!chan->local)
976 goto err_out;
regards,
dan carpenter