Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2047140imm; Thu, 14 Jun 2018 08:00:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLouNhEW3AxMJt1zEQSpyoNZuCcY6CUk7H5hfS5venYMX5czQoSXdqXreqdn+A0moufJBKu X-Received: by 2002:a65:49cb:: with SMTP id t11-v6mr2598974pgs.218.1528988405953; Thu, 14 Jun 2018 08:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528988405; cv=none; d=google.com; s=arc-20160816; b=1EmtAEOh/PZ2TPyE3cWX8Rl+Xhr+Gy4uTzymEsbW4X09LOjN8v65SErbXia6IjQzXV 9c0rfJNMnJ8rfTRxMPGiWAnM/UlZljBqI12zuZ/6aqsAdn0jJQaN7macm5a7VZXfIh0t ka79KLK1xVV0WXxg8ULjV2/vFNXLNzvKwyPvgJtdXRNoBz/9jeqIBr4gSmyvu7V9VWPF cgNNLx6URl/+bibzfTXmLgulLh55TTSjNkq1Cm4ilMv7yQDZcK6+fe2AZi88SBRHNx+e 3FC4wUq4ZolUwxgGL8mRdFrpwBMq3nWGcos2X8w3J3VZlkCRpOqMed40gHRrBFfnhKCH 7J2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=0IyRvMhEgtR9R58YPIFtL7V/V3+3m1wP6JLOcgRaLO4=; b=L+rIZFIe6QT3GEiIigA/dn9xQLDQk86xZHOcVI6F5hSbQPEchnJd645Ty6f9D6UB4G zZJSEJW22FrR/n+94UBV1d39bgwca3AXcj+oLfpZwnqy5Kror4YvnlsI3i38fHvd3Mgp BgHR5KpqFiE6c91T9Fgv7G1B8OUZbj1DBoWTVwNqC6Pqi/fELwu+W00++Om6z9O9PFL9 Z4saZ1VYAOldiK53nZUXCbIuOU1m38Zffk0q26b4Tn3BtujtDAZv7GTKKHwPYPmrPlop ju56u3I0qGMuGxpUX03YNk9rAeQ4XP0Wt9dsTlFdvIqGijN3zmr3LrYmTVRuFgJ1vlwg L7Gg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5-v6si5535521ple.417.2018.06.14.07.59.51; Thu, 14 Jun 2018 08:00:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755370AbeFNO6u (ORCPT + 99 others); Thu, 14 Jun 2018 10:58:50 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:42916 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1755305AbeFNO6t (ORCPT ); Thu, 14 Jun 2018 10:58:49 -0400 Received: (qmail 2501 invoked by uid 2102); 14 Jun 2018 10:58:48 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 14 Jun 2018 10:58:48 -0400 Date: Thu, 14 Jun 2018 10:58:48 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Zhouyang Jia cc: Greg Kroah-Hartman , , , Subject: Re: [PATCH v2] usb: storage: add error handling for kcalloc In-Reply-To: <1528982951-52753-1-git-send-email-jiazhouyang09@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Jun 2018, Zhouyang Jia wrote: > When kcalloc fails, the lack of error-handling code may > cause unexpected results. > > This patch adds error-handling code after calling kcalloc. > > Signed-off-by: Zhouyang Jia > --- > v1->v2: > - Remove pr_warn statement. > --- > drivers/usb/storage/alauda.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c > index 900591d..4e17609 100644 > --- a/drivers/usb/storage/alauda.c > +++ b/drivers/usb/storage/alauda.c > @@ -437,6 +437,9 @@ static int alauda_init_media(struct us_data *us) > + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); > MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); > MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); > + if ((MEDIA_INFO(us).pba_to_lba == NULL) > + || (MEDIA_INFO(us).lba_to_pba == NULL)) > + return USB_STOR_TRANSPORT_ERROR; > > if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) > return USB_STOR_TRANSPORT_ERROR; > Acked-by: Alan Stern