public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
	Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
	Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk,
	v4l-dvb maintainer list <v4l-dvb-maintainer@linuxtv.org>,
	Laurent Pinchart <laurent.pinchart@skynet.be>,
	Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: [patch 42/62] V4L: uvcvideo: Dont free URB buffers on suspend
Date: Wed, 30 Jul 2008 16:59:22 -0700	[thread overview]
Message-ID: <20080730235922.GP12896@suse.de> (raw)
In-Reply-To: <20080730234915.GA12426@suse.de>

[-- Attachment #1: v4l-uvcvideo-don-t-free-urb-buffers-on-suspend.patch --]
[-- Type: text/plain, Size: 5837 bytes --]


2.6.26 -stable review patch.  If anyone has any objections, please let
us know.

------------------
From: Laurent Pinchart <laurent.pinchart@skynet.be>

(cherry picked from commit e01117c81676dc9897f567e32cdc13a26e85280b)

V4L: uvcvideo: Don't free URB buffers on suspend.

All submitted URBs must be killed at suspend time, but URB buffers don't
have to be freed. Avoiding a free on suspend/reallocate on resume lowers
the pressure on system memory.

Signed-off-by: Laurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/media/video/uvc/uvc_video.c |   96 ++++++++++++++++++++++++------------
 drivers/media/video/uvc/uvcvideo.h  |    2 
 2 files changed, 66 insertions(+), 32 deletions(-)

--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -554,9 +554,56 @@ static void uvc_video_complete(struct ur
 }
 
 /*
+ * Free transfer buffers.
+ */
+static void uvc_free_urb_buffers(struct uvc_video_device *video)
+{
+	unsigned int i;
+
+	for (i = 0; i < UVC_URBS; ++i) {
+		if (video->urb_buffer[i]) {
+			usb_buffer_free(video->dev->udev, video->urb_size,
+				video->urb_buffer[i], video->urb_dma[i]);
+			video->urb_buffer[i] = NULL;
+		}
+	}
+
+	video->urb_size = 0;
+}
+
+/*
+ * Allocate transfer buffers. This function can be called with buffers
+ * already allocated when resuming from suspend, in which case it will
+ * return without touching the buffers.
+ *
+ * Return 0 on success or -ENOMEM when out of memory.
+ */
+static int uvc_alloc_urb_buffers(struct uvc_video_device *video,
+	unsigned int size)
+{
+	unsigned int i;
+
+	/* Buffers are already allocated, bail out. */
+	if (video->urb_size)
+		return 0;
+
+	for (i = 0; i < UVC_URBS; ++i) {
+		video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
+			size, GFP_KERNEL, &video->urb_dma[i]);
+		if (video->urb_buffer[i] == NULL) {
+			uvc_free_urb_buffers(video);
+			return -ENOMEM;
+		}
+	}
+
+	video->urb_size = size;
+	return 0;
+}
+
+/*
  * Uninitialize isochronous/bulk URBs and free transfer buffers.
  */
-static void uvc_uninit_video(struct uvc_video_device *video)
+static void uvc_uninit_video(struct uvc_video_device *video, int free_buffers)
 {
 	struct urb *urb;
 	unsigned int i;
@@ -566,19 +613,12 @@ static void uvc_uninit_video(struct uvc_
 			continue;
 
 		usb_kill_urb(urb);
-		/* urb->transfer_buffer_length is not touched by USB core, so
-		 * we can use it here as the buffer length.
-		 */
-		if (video->urb_buffer[i]) {
-			usb_buffer_free(video->dev->udev,
-				urb->transfer_buffer_length,
-				video->urb_buffer[i], urb->transfer_dma);
-			video->urb_buffer[i] = NULL;
-		}
-
 		usb_free_urb(urb);
 		video->urb[i] = NULL;
 	}
+
+	if (free_buffers)
+		uvc_free_urb_buffers(video);
 }
 
 /*
@@ -610,18 +650,13 @@ static int uvc_init_video_isoc(struct uv
 
 	size = npackets * psize;
 
+	if (uvc_alloc_urb_buffers(video, size) < 0)
+		return -ENOMEM;
+
 	for (i = 0; i < UVC_URBS; ++i) {
 		urb = usb_alloc_urb(npackets, gfp_flags);
 		if (urb == NULL) {
-			uvc_uninit_video(video);
-			return -ENOMEM;
-		}
-
-		video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
-			size, gfp_flags, &urb->transfer_dma);
-		if (video->urb_buffer[i] == NULL) {
-			usb_free_urb(urb);
-			uvc_uninit_video(video);
+			uvc_uninit_video(video, 1);
 			return -ENOMEM;
 		}
 
@@ -632,6 +667,7 @@ static int uvc_init_video_isoc(struct uv
 		urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
 		urb->interval = ep->desc.bInterval;
 		urb->transfer_buffer = video->urb_buffer[i];
+		urb->transfer_dma = video->urb_dma[i];
 		urb->complete = uvc_video_complete;
 		urb->number_of_packets = npackets;
 		urb->transfer_buffer_length = size;
@@ -671,20 +707,15 @@ static int uvc_init_video_bulk(struct uv
 	if (size > psize * UVC_MAX_ISO_PACKETS)
 		size = psize * UVC_MAX_ISO_PACKETS;
 
+	if (uvc_alloc_urb_buffers(video, size) < 0)
+		return -ENOMEM;
+
 	pipe = usb_rcvbulkpipe(video->dev->udev, ep->desc.bEndpointAddress);
 
 	for (i = 0; i < UVC_URBS; ++i) {
 		urb = usb_alloc_urb(0, gfp_flags);
 		if (urb == NULL) {
-			uvc_uninit_video(video);
-			return -ENOMEM;
-		}
-
-		video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
-			size, gfp_flags, &urb->transfer_dma);
-		if (video->urb_buffer[i] == NULL) {
-			usb_free_urb(urb);
-			uvc_uninit_video(video);
+			uvc_uninit_video(video, 1);
 			return -ENOMEM;
 		}
 
@@ -692,6 +723,7 @@ static int uvc_init_video_bulk(struct uv
 			video->urb_buffer[i], size, uvc_video_complete,
 			video);
 		urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
+		urb->transfer_dma = video->urb_dma[i];
 
 		video->urb[i] = urb;
 	}
@@ -766,7 +798,7 @@ static int uvc_init_video(struct uvc_vid
 		if ((ret = usb_submit_urb(video->urb[i], gfp_flags)) < 0) {
 			uvc_printk(KERN_ERR, "Failed to submit URB %u "
 					"(%d).\n", i, ret);
-			uvc_uninit_video(video);
+			uvc_uninit_video(video, 1);
 			return ret;
 		}
 	}
@@ -791,7 +823,7 @@ int uvc_video_suspend(struct uvc_video_d
 		return 0;
 
 	video->frozen = 1;
-	uvc_uninit_video(video);
+	uvc_uninit_video(video, 0);
 	usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);
 	return 0;
 }
@@ -920,7 +952,7 @@ int uvc_video_enable(struct uvc_video_de
 	int ret;
 
 	if (!enable) {
-		uvc_uninit_video(video);
+		uvc_uninit_video(video, 1);
 		usb_set_interface(video->dev->udev,
 			video->streaming->intfnum, 0);
 		uvc_queue_enable(&video->queue, 0);
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -602,6 +602,8 @@ struct uvc_video_device {
 
 	struct urb *urb[UVC_URBS];
 	char *urb_buffer[UVC_URBS];
+	dma_addr_t urb_dma[UVC_URBS];
+	unsigned int urb_size;
 
 	__u8 last_fid;
 };

-- 

  parent reply	other threads:[~2008-07-31  0:20 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080730233050.332789722@mini.kroah.org>
2008-07-30 23:49 ` [patch 00/62] 2.6.26-stable review Greg KH
2008-07-30 23:57   ` [patch 01/62] pxamci: trivial fix of DMA alignment register bit clearing Greg KH
2008-07-30 23:57   ` [patch 02/62] udplite: Protection against coverage value wrap-around Greg KH
2008-07-30 23:57   ` [patch 03/62] ipv6: use timer pending Greg KH
2008-07-30 23:57   ` [patch 04/62] ipv6: __KERNEL__ ifdef struct ipv6_devconf Greg KH
2008-07-30 23:57   ` [patch 05/62] hdlcdrv: Fix CRC calculation Greg KH
2008-07-30 23:57   ` [patch 06/62] quota: fix possible infinite loop in quota code Greg KH
2008-07-30 23:58   ` [patch 07/62] isofs: fix minor filesystem corruption Greg KH
2008-07-30 23:58   ` [patch 08/62] KVM: VMX: Fix a wrong usage of vmcs_config Greg KH
2008-07-30 23:58   ` [patch 09/62] KVM: SVM: fix suspend/resume support Greg KH
2008-07-30 23:58   ` [patch 10/62] KVM: mmu_shrink: kvm_mmu_zap_page requires slots_lock to be held Greg KH
2008-07-30 23:58   ` [patch 11/62] KVM: VMX: Add ept_sync_context in flush_tlb Greg KH
2008-07-30 23:58   ` [patch 12/62] KVM: x86 emulator: Fix HLT instruction Greg KH
2008-07-30 23:58   ` [patch 13/62] KVM: MMU: nuke shadowed pgtable pages and ptes on memslot destruction Greg KH
2008-07-30 23:58   ` [patch 14/62] KVM: MMU: Fix potential race setting upper shadow ptes on nonpae hosts Greg KH
2008-07-30 23:58   ` [patch 15/62] Patch Upstream: x86 ptrace: fix PTRACE_GETFPXREGS error Greg KH
2008-07-30 23:58   ` [patch 16/62] rcu: fix rcu_try_flip_waitack_needed() to prevent grace-period stall Greg KH
2008-07-30 23:58   ` [patch 17/62] Fix typos from signal_32/64.h merge Greg KH
2008-07-30 23:58   ` [patch 18/62] x86 reboot quirks: add Dell Precision WorkStation T5400 Greg KH
2008-07-30 23:58   ` [patch 19/62] USB: fix usb serial pm counter decrement for disconnected interfaces Greg KH
2008-07-30 23:58   ` [patch 20/62] x86, suspend, acpi: enter Big Real Mode Greg KH
2008-08-05 12:15     ` Pavel Machek
2008-07-30 23:58   ` [patch 21/62] markers: fix duplicate modpost entry Greg KH
2008-07-30 23:58   ` [patch 22/62] Fix build on COMPAT platforms when CONFIG_EPOLL is disabled Greg KH
2008-07-30 23:58   ` [patch 24/62] cpusets: fix wrong domain attr updates Greg KH
2008-07-30 23:58   ` [patch 25/62] x86: fix crash due to missing debugctlmsr on AMD K6-3 Greg KH
2008-07-30 23:58   ` [patch 23/62] proc: fix /proc/*/pagemap Greg KH
2008-07-30 23:58   ` [patch 26/62] ide-cd: fix oops when using growisofs Greg KH
2008-07-30 23:58   ` [patch 27/62] rtc-at91rm9200: avoid spurious irqs Greg KH
2008-07-30 23:58   ` [patch 28/62] vmlinux.lds: move __attribute__((__cold__)) functions back into final .text section Greg KH
2008-07-30 23:58   ` [patch 29/62] ARM: fix fls() for 64-bit arguments Greg KH
2008-07-30 23:58   ` [patch 30/62] tcp: Clear probes_out more aggressively in tcp_ack() Greg KH
2008-07-30 23:58   ` [patch 31/62] sparc64: Fix lockdep issues in LDC protocol layer Greg KH
2008-07-30 23:59   ` [patch 32/62] sparc64: Fix cpufreq notifier registry Greg KH
2008-07-30 23:59   ` [patch 33/62] sparc64: Do not define BIO_VMERGE_BOUNDARY Greg KH
2008-07-30 23:59   ` [patch 34/62] iop-adma: fix platform driver hotplug/coldplug Greg KH
2008-07-30 23:59   ` [patch 35/62] myri10ge: do not forget to setup the single slice pointers Greg KH
2008-07-30 23:59   ` [patch 36/62] myri10ge: do not use mgp->max_intr_slots before loading the firmware Greg KH
2008-07-30 23:59   ` [patch 37/62] ALSA: trident - pause s/pdif output Greg KH
2008-07-30 23:59   ` [patch 38/62] V4L: cx18: Upgrade to newer firmware & update documentation Greg KH
2008-07-30 23:59   ` [patch 39/62] DVB: dib0700: add support for Hauppauge Nova-TD Stick 52009 Greg KH
2008-07-30 23:59   ` [patch 40/62] V4L: uvcvideo: Fix a buffer overflow in format descriptor parsing Greg KH
2008-07-30 23:59   ` [patch 41/62] V4L: uvcvideo: Use GFP_NOIO when allocating memory during resume Greg KH
2008-07-30 23:59   ` Greg KH [this message]
2008-07-30 23:59   ` [patch 43/62] V4L: uvcvideo: Make input device support optional Greg KH
2008-07-30 23:59   ` [patch 44/62] V4L: uvcvideo: Add support for Medion Akoya Mini E1210 integrated webcam Greg KH
2008-07-30 23:59   ` [patch 45/62] V4L: saa7134: Copy tuner data earlier to avoid overwriting manual tuner type Greg KH
2008-07-30 23:59   ` [patch 46/62] V4L: cx23885: Bugfix for concurrent use of /dev/video0 and /dev/video1 Greg KH
2008-07-30 23:59   ` [patch 47/62] DVB: cx23885: Ensure PAD_CTRL is always reset to a sensible default Greg KH
2008-07-30 23:59   ` [patch 48/62] DVB: cx23885: DVB Transport cards using DVB port VIDB/TS1 did not stream Greg KH
2008-07-30 23:59   ` [patch 49/62] DVB: cx23885: Reallocated the sram to avoid concurrent VIDB/C issues Greg KH
2008-07-30 23:59   ` [patch 50/62] DVB: cx23885: SRAM changes for the 885 and 887 silicon parts Greg KH
2008-07-30 23:59   ` [patch 51/62] x86: fix kernel_physical_mapping_init() for large x86 systems Greg KH
2008-07-30 23:59   ` [patch 52/62] eCryptfs: use page_alloc not kmalloc to get a page of memory Greg KH
2008-07-30 23:59   ` [patch 53/62] UML - Fix boot crash Greg KH
2008-07-30 23:59   ` [patch 54/62] ixgbe: remove device ID for unsupported device Greg KH
2008-07-30 23:59   ` [patch 55/62] mpc52xx_psc_spi: fix block transfer Greg KH
2008-07-30 23:59   ` [patch 56/62] tmpfs: fix kernel BUG in shmem_delete_inode Greg KH
2008-07-30 23:59   ` [patch 57/62] markers: fix markers read barrier for multiple probes Greg KH
2008-07-31  0:00   ` [patch 58/62] VFS: increase pseudo-filesystem block size to PAGE_SIZE Greg KH
2008-07-31  0:00   ` [patch 59/62] cpufreq acpi: only call _PPC after cpufreq ACPI init funcs got called already Greg KH
2008-07-31  0:00   ` [patch 60/62] b43legacy: Release mutex in error handling code Greg KH
2008-07-31  0:00   ` [patch 61/62] ath5k: dont enable MSI, we cannot handle it yet Greg KH
2008-07-31  0:00   ` [patch 62/62] Fix off-by-one error in iov_iter_advance() Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080730235922.GP12896@suse.de \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=cavokz@gmail.com \
    --cc=cebbert@redhat.com \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=eteo@redhat.com \
    --cc=jake@lwn.net \
    --cc=jmforbes@linuxtx.org \
    --cc=laurent.pinchart@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rbranco@la.checkpoint.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=v4l-dvb-maintainer@linuxtv.org \
    --cc=w@1wt.eu \
    --cc=zwane@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox