diff mbox

mptlan: add checks for dma mapping errors

Message ID 1453503833-9945-1-git-send-email-khoroshilov@ispras.ru (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Alexey Khoroshilov Jan. 22, 2016, 11:03 p.m. UTC
mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check
if mapping dma memory succeed.
The patch adds the checks and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/message/fusion/mptlan.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

kernel test robot Jan. 22, 2016, 11:20 p.m. UTC | #1
Hi Alexey,

[auto build test WARNING on v4.4-rc8]
[also build test WARNING on next-20160122]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Alexey-Khoroshilov/mptlan-add-checks-for-dma-mapping-errors/20160123-070633
config: xtensa-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=xtensa 

All warnings (new ones prefixed by >>):

   drivers/message/fusion/mptlan.c: In function 'mpt_lan_sdu_send':
>> drivers/message/fusion/mptlan.c:737:6: warning: passing argument 1 of 'dma_mapping_error' from incompatible pointer type
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
         ^
   In file included from arch/xtensa/include/asm/dma-mapping.h:33:0,
                    from include/linux/dma-mapping.h:87,
                    from include/linux/skbuff.h:34,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:17,
                    from include/linux/ethtool.h:16,
                    from include/linux/netdevice.h:42,
                    from drivers/message/fusion/mptlan.h:58,
                    from drivers/message/fusion/mptlan.c:55:
   include/asm-generic/dma-mapping-common.h:316:19: note: expected 'struct device *' but argument is of type 'struct pci_dev *'
    static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
                      ^

vim +/dma_mapping_error +737 drivers/message/fusion/mptlan.c

   721		ctx = priv->mpt_txfidx[priv->mpt_txfidx_tail--];
   722		spin_unlock_irqrestore(&priv->txfidx_lock, flags);
   723	
   724	//	dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
   725	//			IOC_AND_NETDEV_NAMES_s_s(dev)));
   726	
   727		pSendReq = (LANSendRequest_t *) mf;
   728	
   729		/* Set the mac.raw pointer, since this apparently isn't getting
   730		 * done before we get the skb. Pull the data pointer past the mac data.
   731		 */
   732		skb_reset_mac_header(skb);
   733		skb_pull(skb, 12);
   734	
   735	        dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
   736				     PCI_DMA_TODEVICE);
 > 737		if (dma_mapping_error(mpt_dev->pcidev, dma)) {
   738			netif_stop_queue(dev);
   739	
   740			printk (KERN_ERR "%s: dma mapping failed\n", __func__);
   741			return NETDEV_TX_BUSY;
   742		}
   743	
   744		priv->SendCtl[ctx].skb = skb;
   745		priv->SendCtl[ctx].dma = dma;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Jan. 23, 2016, 2:03 a.m. UTC | #2
Hi Alexey,

[auto build test WARNING on v4.4-rc8]
[also build test WARNING on next-20160122]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Alexey-Khoroshilov/mptlan-add-checks-for-dma-mapping-errors/20160123-070633
config: x86_64-randconfig-s1-01230930 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/message/fusion/mptlan.h:55,
                    from drivers/message/fusion/mptlan.c:55:
   drivers/message/fusion/mptlan.c: In function 'mpt_lan_sdu_send':
   drivers/message/fusion/mptlan.c:737:24: warning: passing argument 1 of 'dma_mapping_error' from incompatible pointer type [-Wincompatible-pointer-types]
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
                           ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
>> drivers/message/fusion/mptlan.c:737:2: note: in expansion of macro 'if'
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
     ^
   In file included from arch/x86/include/asm/dma-mapping.h:49:0,
                    from include/linux/dma-mapping.h:87,
                    from include/linux/skbuff.h:34,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:17,
                    from include/linux/ethtool.h:16,
                    from include/linux/netdevice.h:42,
                    from drivers/message/fusion/mptlan.h:58,
                    from drivers/message/fusion/mptlan.c:55:
   include/asm-generic/dma-mapping-common.h:316:19: note: expected 'struct device *' but argument is of type 'struct pci_dev *'
    static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
                      ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/message/fusion/mptlan.h:55,
                    from drivers/message/fusion/mptlan.c:55:
   drivers/message/fusion/mptlan.c:737:24: warning: passing argument 1 of 'dma_mapping_error' from incompatible pointer type [-Wincompatible-pointer-types]
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
                           ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
>> drivers/message/fusion/mptlan.c:737:2: note: in expansion of macro 'if'
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
     ^
   In file included from arch/x86/include/asm/dma-mapping.h:49:0,
                    from include/linux/dma-mapping.h:87,
                    from include/linux/skbuff.h:34,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:17,
                    from include/linux/ethtool.h:16,
                    from include/linux/netdevice.h:42,
                    from drivers/message/fusion/mptlan.h:58,
                    from drivers/message/fusion/mptlan.c:55:
   include/asm-generic/dma-mapping-common.h:316:19: note: expected 'struct device *' but argument is of type 'struct pci_dev *'
    static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
                      ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/list.h:4,
                    from include/linux/module.h:9,
                    from drivers/message/fusion/mptlan.h:55,
                    from drivers/message/fusion/mptlan.c:55:
   drivers/message/fusion/mptlan.c:737:24: warning: passing argument 1 of 'dma_mapping_error' from incompatible pointer type [-Wincompatible-pointer-types]
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
                           ^
   include/linux/compiler.h:158:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^
>> drivers/message/fusion/mptlan.c:737:2: note: in expansion of macro 'if'
     if (dma_mapping_error(mpt_dev->pcidev, dma)) {
     ^
   In file included from arch/x86/include/asm/dma-mapping.h:49:0,
                    from include/linux/dma-mapping.h:87,
                    from include/linux/skbuff.h:34,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:17,
                    from include/linux/ethtool.h:16,
                    from include/linux/netdevice.h:42,
                    from drivers/message/fusion/mptlan.h:58,
                    from drivers/message/fusion/mptlan.c:55:
   include/asm-generic/dma-mapping-common.h:316:19: note: expected 'struct device *' but argument is of type 'struct pci_dev *'
    static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
                      ^

vim +/if +737 drivers/message/fusion/mptlan.c

   721		ctx = priv->mpt_txfidx[priv->mpt_txfidx_tail--];
   722		spin_unlock_irqrestore(&priv->txfidx_lock, flags);
   723	
   724	//	dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
   725	//			IOC_AND_NETDEV_NAMES_s_s(dev)));
   726	
   727		pSendReq = (LANSendRequest_t *) mf;
   728	
   729		/* Set the mac.raw pointer, since this apparently isn't getting
   730		 * done before we get the skb. Pull the data pointer past the mac data.
   731		 */
   732		skb_reset_mac_header(skb);
   733		skb_pull(skb, 12);
   734	
   735	        dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
   736				     PCI_DMA_TODEVICE);
 > 737		if (dma_mapping_error(mpt_dev->pcidev, dma)) {
   738			netif_stop_queue(dev);
   739	
   740			printk (KERN_ERR "%s: dma mapping failed\n", __func__);
   741			return NETDEV_TX_BUSY;
   742		}
   743	
   744		priv->SendCtl[ctx].skb = skb;
   745		priv->SendCtl[ctx].dma = dma;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index cbe96072a6cc..076bf45a95fe 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -734,6 +734,12 @@  mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
 
         dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
 			     PCI_DMA_TODEVICE);
+	if (dma_mapping_error(mpt_dev->pcidev, dma)) {
+		netif_stop_queue(dev);
+
+		printk (KERN_ERR "%s: dma mapping failed\n", __func__);
+		return NETDEV_TX_BUSY;
+	}
 
 	priv->SendCtl[ctx].skb = skb;
 	priv->SendCtl[ctx].dma = dma;
@@ -1232,6 +1238,14 @@  mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv)
 
 				dma = pci_map_single(mpt_dev->pcidev, skb->data,
 						     len, PCI_DMA_FROMDEVICE);
+				if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) {
+					printk (KERN_WARNING
+						MYNAM "/%s: dma mapping failed\n",
+						__func__);
+					priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
+					spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
+					break;
+				}
 
 				priv->RcvCtl[ctx].skb = skb;
 				priv->RcvCtl[ctx].dma = dma;