Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp994079imm; Fri, 15 Jun 2018 09:26:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJdAUCQ18mmvmX6VkbeL6cuySZZoVOldAyBeLUBX06Bd2clkBuSQ/Y0fmJfpicIr7GZgOCC X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr2798340plq.215.1529080012035; Fri, 15 Jun 2018 09:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529080011; cv=none; d=google.com; s=arc-20160816; b=Y8fBJSE6y1+J2hKugzq5ch/L7aFIVWVNAr9MnQBGdM7aLTuWEB3QhO22rz+x/cAHo+ 4yyJJUo1t9shLwywZwA7xW1svfJgmGQ4WDgK6PIlHOlhvyh1jHVOIdQ/qfil6BefyG8m Q0lGDsvZ+iByuS+VVE8hZMzcnl6XGyovjF3bEW+vSxNlXfC1SCeL5HlOV7Y7hStkEuWo oTSKNyLgPDqXd3hf0d9O3ZOdpdf8INYDYzHskaBG6CIOaHJ1q7dXYHbNfn/CWry17ucb EiCXMl1DQz2JUB0c59zkZ6RcxtK33JWGYKqvbJx2ruuRTHo+pcDbHEwfLyt88brfC37a Y1Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature:arc-authentication-results; bh=7OM7+QLbGlCqxjx0ZYq68xNddQKGNGGcB3U9nffnPvo=; b=Rx2t6HOddHFPV69+Ksvnic5l5+wrBJ9FgZYn99Owr5KdjcsIH1d7E1ia+HiFBmgDlj gmPjpb6jViGnZ07IRjSTh8WJtjifQaCvQgBxYvRFZNWA1y3SFyfP2EhHgUYD3XpNyNp4 TgW67y3bsSSi1l45nqUYblvGOclusg/C41qxwK0+NcfGqBcufxOdNkDVuunOIRkNo7sm b0qW36xP+HvNMGpSnQVUv/80ixOpKpgyIqw9GZh4hFfbwVTAfkcju0JN21J4LXlZWjWt ivW8kksdk6NAZWwyYab+aigP/5XN+dakp3kn0CD/a1gGvozsZfMR9E81vxQEXFdtbmKH nyiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HPw8XZYn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3-v6si6800824pgp.102.2018.06.15.09.26.37; Fri, 15 Jun 2018 09:26:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HPw8XZYn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966024AbeFOQZq (ORCPT + 99 others); Fri, 15 Jun 2018 12:25:46 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:37637 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966009AbeFOQZp (ORCPT ); Fri, 15 Jun 2018 12:25:45 -0400 Received: by mail-pf0-f193.google.com with SMTP id y5-v6so5108291pfn.4 for ; Fri, 15 Jun 2018 09:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7OM7+QLbGlCqxjx0ZYq68xNddQKGNGGcB3U9nffnPvo=; b=HPw8XZYnXwzhKPuj8+H+LmxflSdfST2EXZoCOVv1ZSBbbl4OVqS6x9rHfvT+AX4cPf c/ly5uxNVMxHrdwSUbAQYpXpuTCLPf5Kn/jHs0jQbTObQHvNGJLA9MrblX6lKkWeSwHn STYSaXmPG+0qNQDPLQwonHOmLbyfmxhpULAoXmGDiy8vWUczJpO+UznGiuCR9K4WiabO AHcdveoAQbpqCuM3nQiS2Vn9kRbzIdJD4IcMo08hSoClOYmm3X2IKG0gkxaf3uHOHYTn XlkgOXm2dyMT+BLzbbR3r30bJwFZH3BKvAaTCsNkBkOquTG//kqc4hrmwczZ6zgSgCxM xvCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7OM7+QLbGlCqxjx0ZYq68xNddQKGNGGcB3U9nffnPvo=; b=PnGDrhzInbiiGz4LdvBKLaFdNzUtk68I2CmuJnXHpQSYxm4o1KYK9dmcrVW30AObiI H2y4Z7Sr4ht25DmeZ7Qz91UE1OPQchMa/TncVAd+TWPDBB33CZRV3W5CyB9wQqwph69k 40K8opRSraNavKbKnfzk5KJ79+Yg+EMTo1kNyNqIqtWbtKirk2e0IjJIQEgSeUo7ZHeo vcw2FhkinuQbzEpE4MHlh9lYk9VuANGKDOnELyDTH0AgVyBP6tV/e1tJTkK6VkawdYL2 Mxo0CYblc+uR7FDyaDgkoikpf4ZApHu5jiKN//yBsYY6mM32ER9yabBJ0eVnEQJ0nlpX qQhQ== X-Gm-Message-State: APt69E1loTkE2s4we3Cb2VvWE5spnV2RY+Te5m7kXEGKXZT/P2BmCyk0 QdwLSTNn9klz6O7tW9mxzUk= X-Received: by 2002:a65:6604:: with SMTP id w4-v6mr2229559pgv.346.1529079944586; Fri, 15 Jun 2018 09:25:44 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id l85-v6sm15218208pfk.79.2018.06.15.09.25.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jun 2018 09:25:43 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Greg Kroah-Hartman , Christophe JAILLET , Kees Cook , Jia-Ju Bai , Shreeya Patel , Colin Ian King , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] staging: rtl8192u: add error handling for usb_alloc_urb Date: Sat, 16 Jun 2018 00:25:23 +0800 Message-Id: <1529079930-58587-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528705874-34845-1-git-send-email-jiazhouyang09@gmail.com> References: <1528705874-34845-1-git-send-email-jiazhouyang09@gmail.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When usb_alloc_urb fails, the lack of error-handling code may cause unexpected results. This patch adds error-handling code after calling usb_alloc_urb. Signed-off-by: Zhouyang Jia --- v1->v2: - Fix memory leak. --- drivers/staging/rtl8192u/r8192U_core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 7a0dbc0..6afab4e 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -1648,13 +1648,17 @@ static short rtl8192_usb_initendpoints(struct net_device *dev) #ifndef JACKSON_NEW_RX for (i = 0; i < (MAX_RX_URB + 1); i++) { priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); - if (!priv->rx_urb[i]) + if (!priv->rx_urb[i]) { + kfree(priv->rx_urb); return -ENOMEM; + } priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL); - if (!priv->rx_urb[i]->transfer_buffer) + if (!priv->rx_urb[i]->transfer_buffer) { + kfree(priv->rx_urb); return -ENOMEM; + } priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE; } @@ -1666,9 +1670,17 @@ static short rtl8192_usb_initendpoints(struct net_device *dev) void *oldaddr, *newaddr; priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL); + if (!priv->rx_urb[16]) { + kfree(priv->rx_urb); + return -ENOMEM; + } + priv->oldaddr = kmalloc(16, GFP_KERNEL); - if (!priv->oldaddr) + if (!priv->oldaddr) { + kfree(priv->rx_urb); return -ENOMEM; + } + oldaddr = priv->oldaddr; align = ((long)oldaddr) & 3; if (align) { -- 2.7.4