[PATCH] usb: gadget: fix code so the warnings disappear

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use proper printf length modifier for the dma_addr_t thingy. It is cast
to u64 since dma_addr_t can be > 32bit on 32bit archs.

|usb/gadget/net2272.c: In function 'net2272_kick_dma':
|usb/gadget/net2272.c:740:2: warning: format '%08x' expects type 'long unsigned int', but argument 6 has type 'dma_addr_t'
|usb/gadget/net2272.c: In function 'net2272_queue':
|usb/gadget/net2272.c:859:2: warning: format '%08x' expects type 'unsigned int', but argument 8 has type 'dma_addr_t'
|usb/gadget/ci13xxx_udc.c: In function 'show_registers':
|usb/gadget/ci13xxx_udc.c:1242:1: warning: the frame size of 2064 bytes is larger than 1024 bytes
|usb/gadget/fusb300_udc.c: In function â??fusb300_fill_idma_prdtblâ??:
|usb/gadget/fusb300_udc.c:1074:12: warning: cast from pointer to integer of different size
|usb/gadget/fusb300_udc.c: At top level:
|usb/gadget/fusb300_udc.c:771:13: warning: â??fusb300_wrfifoâ?? defined but not used
|usb/gadget/fusb300_udc.c:1027:13: warning: â??fusb300_set_ep_bycntâ?? defined but not used
|usb/gadget/langwell_udc.c: In function 'queue_dtd':
|usb/gadget/langwell_udc.c:596:79: warning: cast from pointer to integer of different size
|usb/gadget/langwell_udc.c: In function 'langwell_ep_dequeue':
|usb/gadget/langwell_udc.c:922:11: warning: cast from pointer to integer of different size
|usb/gadget/langwell_udc.c: In function 'langwell_udc_probe':
|usb/gadget/langwell_udc.c:3274:2: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'
|usb/gadget/langwell_udc.c:3289:2: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'
|usb/gadget/langwell_udc.c: In function 'langwell_udc_resume':
|usb/gadget/langwell_udc.c:3473:2: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'
|usb/gadget/langwell_udc.c:3487:2: warning: format '%d' expects type 'int', but argument 4 has type 'size_t'

fusb300_udc is a little more:
- remove pointer u32 abuse in fusb300_fill_idma_prdtbl(). It is assigned
  the dma_addr to a pointer and then back. Poor families may have to
  recycle variables but we don't
- don't free req.buf in error case. We don't do it in the ok case so it
  is probably wring to do it in error case.
- return in error case. There is no reason to continue without data and
  performing ops on an invalid pointer.
- The if (d) statement is bogus since an invalid DMA pointer is ~0 on
  some architecutres. And since we return for the invalid case we don't
  need it.
- #if 0 unused code. If +2 cycles it is still there then I'm going to
  nuke it. If it is required due to broken DMA engine make an
  platform_data option.

Both, langwell and fusb depend on not PHYS_ADDR_T_64BIT since they don't
handle the larger addr space correctly. This should be fixed for them if
they wish to work properly on bigmem kernels.

Cc: Mike Frysinger <vapier@xxxxxxxxxx>
Cc: Pavankumar Kondeti <pkondeti@xxxxxxxxxxxxxx>
Cc: Yuan-Hsin Chen <yhchen@xxxxxxxxxxxxxxxx>
Cc: Alan Cox <alan@xxxxxxxxxxxxxxx>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
Greg, are all of them addressed?

 drivers/usb/gadget/Kconfig        |    2 ++
 drivers/usb/gadget/ci13xxx_udc.c  |   12 ++++++++++--
 drivers/usb/gadget/fusb300_udc.c  |   26 +++++++++++---------------
 drivers/usb/gadget/langwell_udc.c |   12 ++++++------
 drivers/usb/gadget/net2272.c      |    8 ++++----
 5 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 46a253a..b0594d9 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -157,6 +157,7 @@ config USB_FSL_USB2
 
 config USB_FUSB300
 	tristate "Faraday FUSB300 USB Peripheral Controller"
+	depends on !PHYS_ADDR_T_64BIT
 	select USB_GADGET_DUALSPEED
 	help
 	   Faraday usb device controller FUSB300 driver
@@ -425,6 +426,7 @@ config USB_GOKU
 config USB_LANGWELL
 	tristate "Intel Langwell USB Device Controller"
 	depends on PCI
+	depends on !PHYS_ADDR_T_64BIT
 	select USB_GADGET_DUALSPEED
 	help
 	   Intel Langwell USB Device Controller is a High-Speed USB
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 0824716..1265a85 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -1214,12 +1214,13 @@ static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL);
  *
  * Check "device.h" for details
  */
+#define DUMP_ENTRIES	512
 static ssize_t show_registers(struct device *dev,
 			      struct device_attribute *attr, char *buf)
 {
 	struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev);
 	unsigned long flags;
-	u32 dump[512];
+	u32 *dump;
 	unsigned i, k, n = 0;
 
 	dbg_trace("[%s] %p\n", __func__, buf);
@@ -1228,8 +1229,14 @@ static ssize_t show_registers(struct device *dev,
 		return 0;
 	}
 
+	dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL);
+	if (!dump) {
+		dev_err(dev, "%s: out of memory\n", __func__);
+		return 0;
+	}
+
 	spin_lock_irqsave(udc->lock, flags);
-	k = hw_register_read(dump, sizeof(dump)/sizeof(u32));
+	k = hw_register_read(dump, DUMP_ENTRIES);
 	spin_unlock_irqrestore(udc->lock, flags);
 
 	for (i = 0; i < k; i++) {
@@ -1237,6 +1244,7 @@ static ssize_t show_registers(struct device *dev,
 			       "reg[0x%04X] = 0x%08X\n",
 			       i * (unsigned)sizeof(u32), dump[i]);
 	}
+	kfree(dump);
 
 	return n;
 }
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index 06353e7..277ebaa 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -767,6 +767,7 @@ static void fusb300_rdfifo(struct fusb300_ep *ep,
 	} while (!reg);
 }
 
+#if 0
 /* write data to fifo */
 static void fusb300_wrfifo(struct fusb300_ep *ep,
 			   struct fusb300_request *req)
@@ -816,6 +817,7 @@ static void fusb300_wrfifo(struct fusb300_ep *ep,
 		i++;
 	} while (!reg);
 }
+#endif
 
 static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep)
 {
@@ -1024,6 +1026,7 @@ static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
 	return ret;
 }
 
+#if 0
 static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
 {
 	struct fusb300 *fusb300 = ep->fusb300;
@@ -1034,6 +1037,7 @@ static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
 
 	iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
 }
+#endif
 
 static void done(struct fusb300_ep *ep, struct fusb300_request *req,
 		 int status)
@@ -1058,8 +1062,8 @@ static void done(struct fusb300_ep *ep, struct fusb300_request *req,
 		fusb300_set_cxdone(ep->fusb300);
 }
 
-void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
-			struct fusb300_request *req)
+static void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, dma_addr_t d,
+		u32 len)
 {
 	u32 value;
 	u32 reg;
@@ -1071,10 +1075,9 @@ void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
 		reg &= FUSB300_EPPRD0_H;
 	} while (reg);
 
-	iowrite32((u32) req->req.buf, ep->fusb300->reg +
-		FUSB300_OFFSET_EPPRD_W1(ep->epnum));
+	iowrite32(d, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W1(ep->epnum));
 
-	value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H |
+	value = FUSB300_EPPRD0_BTC(len) | FUSB300_EPPRD0_H |
 		FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
 	iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
 
@@ -1111,13 +1114,12 @@ static void  fusb300_set_idma(struct fusb300_ep *ep,
 			struct fusb300_request *req)
 {
 	dma_addr_t d;
-	u8 *tmp = NULL;
 
 	d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
 
 	if (dma_mapping_error(NULL, d)) {
-		kfree(req->req.buf);
 		printk(KERN_DEBUG "dma_mapping_error\n");
+		return;
 	}
 
 	dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
@@ -1125,17 +1127,11 @@ static void  fusb300_set_idma(struct fusb300_ep *ep,
 	fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
 		FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
 
-	tmp = req->req.buf;
-	req->req.buf = (u8 *)d;
-
-	fusb300_fill_idma_prdtbl(ep, req);
+	fusb300_fill_idma_prdtbl(ep, d, req->req.length);
 	/* check idma is done */
 	fusb300_wait_idma_finished(ep);
 
-	req->req.buf = tmp;
-
-	if (d)
-		dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
+	dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
 }
 
 static void in_ep_fifo_handler(struct fusb300_ep *ep)
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index d8403ae..034bb3d 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -593,8 +593,8 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
 		/* ep0 */
 		dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep));
 
-	dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n",
-			i, (u32)&(dev->ep_dqh[i]));
+	dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%p\n",
+			i, &dev->ep_dqh[i]);
 
 	bit_mask = is_in(ep) ?
 		(1 << (ep->ep_num + 16)) : (1 << (ep->ep_num));
@@ -3271,7 +3271,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
 
 	/* allocate device dQH memory */
 	size = dev->ep_max * sizeof(struct langwell_dqh);
-	dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
+	dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size);
 	if (size < DQH_ALIGNMENT)
 		size = DQH_ALIGNMENT;
 	else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3286,7 +3286,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
 		goto error;
 	}
 	dev->ep_dqh_size = size;
-	dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
+	dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size);
 
 	/* initialize ep0 status request structure */
 	dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL);
@@ -3470,7 +3470,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
 
 	/* allocate device dQH memory */
 	size = dev->ep_max * sizeof(struct langwell_dqh);
-	dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
+	dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size);
 	if (size < DQH_ALIGNMENT)
 		size = DQH_ALIGNMENT;
 	else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3484,7 +3484,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
 		return -ENOMEM;
 	}
 	dev->ep_dqh_size = size;
-	dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
+	dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size);
 
 	/* create dTD dma_pool resource */
 	dev->dtd_pool = dma_pool_create("langwell_dtd",
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index 6065bdf..b1792c6 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -737,8 +737,8 @@ net2272_kick_dma(struct net2272_ep *ep, struct net2272_request *req)
 	if (req->req.length & 1)
 		return -EINVAL;
 
-	dev_vdbg(ep->dev->dev, "kick_dma %s req %p dma %08x\n",
-		ep->ep.name, req, req->req.dma);
+	dev_vdbg(ep->dev->dev, "kick_dma %s req %p dma %08llx\n",
+		ep->ep.name, req, (u64)req->req.dma);
 
 	net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS);
 
@@ -856,9 +856,9 @@ net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 		req->mapped = 1;
 	}
 
-	dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08x %s\n",
+	dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08llx %s\n",
 		_ep->name, _req, _req->length, _req->buf,
-		_req->dma, _req->zero ? "zero" : "!zero");
+		(u64)_req->dma, _req->zero ? "zero" : "!zero");
 
 	spin_lock_irqsave(&dev->lock, flags);
 
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux