Skip to contentSkip to conversation

NTB: Use unique DMA channels for TX and RX

DISCUSSION Dan Carpenter 2 participants 2 messages Sep 16, 2015 NTB driver core

lore
Share & tools
lore
#0 lore raw

Hello Dave Jiang,

This is a semi-automatic email about new static checker warnings.

The patch 569410ca756c: "NTB: Use unique DMA channels for TX and RX" from Jul 13, 2015, leads to the following Smatch complaint:

drivers/ntb/ntb_transport.c:2008 ntb_transport_max_size()

	 error: we previously assumed 'qp->tx_dma_chan' could be null (see line 2005)

drivers/ntb/ntb_transport.c
2004
2005 if (!qp->tx_dma_chan && !qp->rx_dma_chan)

Patch adds new checks for NULL. Was || intended here perhaps?

2006 return qp->tx_max_frame - sizeof(struct ntb_payload_header);
2007
2008 copy_align = max(qp->tx_dma_chan->device->copy_align,
2009 qp->rx_dma_chan->device->copy_align);

Patch adds unchecked dereferences.

2010

regards,
dan carpenter

#1 lore raw

From: [email protected] On Behalf Of Dan Carpenter

Quoted 9 lines

Subject: re: NTB: Use unique DMA channels for TX and RX

drivers/ntb/ntb_transport.c:2008 ntb_transport_max_size()

	 error: we previously assumed 'qp->tx_dma_chan' could be null (see

line 2005)

drivers/ntb/ntb_transport.c
2004
2005 if (!qp->tx_dma_chan && !qp->rx_dma_chan)

I seem to recall commenting on this in patch v1:

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-	if (!qp->dma_chan)
+	if (!qp->tx_dma_chan && !qp->rx_dma_chan)

Unusual to see "if (not && not)" in code, but it looks correct in this case.

if (no dma at all)

	return without any alignment restriction;

Is that right?

Maybe I was wrong to say "looks correct" because this static checker warning sure looks real.

Quoted 8 lines

Patch adds new checks for NULL. Was || intended here perhaps?

2006 return qp->tx_max_frame - sizeof(struct
ntb_payload_header);
2007
2008 copy_align = max(qp->tx_dma_chan->device->copy_align,
2009 qp->rx_dma_chan->device->copy_align);

I think this is the part that actually needs to be fixed. Maybe this whole function should be:

copy_align = max(dma_copy_align(qp->tx_dma_chan),

                 dma_copy_align(qp->rx_dma_chan));

where dma_copy_align is:

if (!chan)

        return 1;

return chan->device->copy_align;

Quoted 5 lines

Patch adds unchecked dereferences.

2010