From patchwork Mon Aug 20 01:23:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 1345431 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B7D15DF264 for ; Mon, 20 Aug 2012 01:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761Ab2HTBYW (ORCPT ); Sun, 19 Aug 2012 21:24:22 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:34049 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336Ab2HTBYW (ORCPT ); Sun, 19 Aug 2012 21:24:22 -0400 Received: by yhmm54 with SMTP id m54so4796712yhm.19 for ; Sun, 19 Aug 2012 18:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=g1BBZutkQKq3BcHypQv0mFBBkJTh/RmzWm34XzAr0h4=; b=zB/ZmvmruuRKFgve5qKYdMdEY8V7TT4V02siLt3ND6aajd52/uCcs2YihJN7LzsEGf WdLITSUpDsOlxfIJug08xPBfBPSWRozXdwAaf6Y4gi3qAjkD1KVHrjmDETedLS0KK5WV P/ahwrqtXB3XJWKxhMiDhb//EbfXK/H7k6NqC4WlNsYYcG24bR2003iVYCtDZHYmZcJa kdxP3ZjtTwkz0dN5Q5t15+oV+T/TT6cm4eCUiAAhzYuMbQbn0koUivzYOqKwNUVoUypt Dsrx+RlE/YlvAryYKyxIIkYi3U+5YUaKBoewp3XBzVHtegWlUoLk0dWizBbYtPyBqgqU Y1HA== Received: by 10.236.73.72 with SMTP id u48mr19323406yhd.71.1345425861565; Sun, 19 Aug 2012 18:24:21 -0700 (PDT) Received: from localhost.cpe.express.com.ar ([200.81.126.15]) by mx.google.com with ESMTPS id b46sm26820855yhm.3.2012.08.19.18.24.13 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Aug 2012 18:24:21 -0700 (PDT) From: Ezequiel Garcia To: , Mauro Carvalho Chehab Cc: Ezequiel Garcia Subject: [PATCH 2/4] stk1160: Handle urb allocation failure condition properly Date: Sun, 19 Aug 2012 22:23:44 -0300 Message-Id: <1345425826-13429-2-git-send-email-elezegarcia@gmail.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1345425826-13429-1-git-send-email-elezegarcia@gmail.com> References: <1345425826-13429-1-git-send-email-elezegarcia@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When an urb buffer can't be allocated, the currently allocated buffer count must be saved so they can properly released. Moreover, it's sufficient to call stk1160_free_isoc to have all urb buffers released. Signed-off-by: Ezequiel Garcia --- drivers/media/usb/stk1160/stk1160-video.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c index 022092a..8bdfb02 100644 --- a/drivers/media/usb/stk1160/stk1160-video.c +++ b/drivers/media/usb/stk1160/stk1160-video.c @@ -462,8 +462,7 @@ int stk1160_alloc_isoc(struct stk1160 *dev) urb = usb_alloc_urb(max_packets, GFP_KERNEL); if (!urb) { stk1160_err("cannot alloc urb[%d]\n", i); - stk1160_uninit_isoc(dev); - return -ENOMEM; + goto free_i_bufs; } dev->isoc_ctl.urb[i] = urb; @@ -474,10 +473,9 @@ int stk1160_alloc_isoc(struct stk1160 *dev) dev->isoc_ctl.transfer_buffer[i] = kmalloc(sb_size, GFP_KERNEL); #endif if (!dev->isoc_ctl.transfer_buffer[i]) { - stk1160_err("cannot alloc %d bytes for tx buffer\n", - sb_size); - stk1160_uninit_isoc(dev); - return -ENOMEM; + stk1160_err("cannot alloc %d bytes for tx[%d] buffer\n", + sb_size, i); + goto free_i_bufs; } memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); @@ -514,5 +512,11 @@ int stk1160_alloc_isoc(struct stk1160 *dev) dev->isoc_ctl.num_bufs = num_bufs; return 0; + +free_i_bufs: + /* Save the allocated buffers so far, so we can properly free them */ + dev->isoc_ctl.num_bufs = i+1; + stk1160_free_isoc(dev); + return -ENOMEM; }