Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5415182imm; Tue, 12 Jun 2018 07:32:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIz81XjelvxRWYoFOf/uwyleG+a0p2npMCC6KTZUQPU//6q7nd6/LgD5QiUwR8ODe9YZZR3 X-Received: by 2002:a17:902:294a:: with SMTP id g68-v6mr753361plb.58.1528813932246; Tue, 12 Jun 2018 07:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528813932; cv=none; d=google.com; s=arc-20160816; b=e7tF6iXsrgOIXfPxxHG0XdszpnZKjXJE6JQldorj/cQfqG2n7njntHyKvgfTalugoe Uhumrrjn0bNFMUUabO5EsSBqA4SD4v7LmyMXC3Me8hjYbcg7cWpTbdDFkOrR9ReGuESt Uefy+flAQK+XImS3VN8kK+u1nOkdo5OgAkZtAFSqZ5pEdoICCXiHdhl832jJM4y1C1aF PnLyV4gdR0jsyX8eL+Fwqwr27UbgAywHxI0wnkhxpzfFl3bgRWT8IjXcRJT9gZXGy3K4 QPZvSIMpmpnP8FLK5XYpuo99dLKxSJ7Wcgd0TPPbTeznu4nrMyL0U+ylh/ZeYwHpwFdK etaQ== 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=IxvkLRIjeohHgbd5C5LdIAdHn70X3zNVKfqtKvxGC08=; b=bOtAe8QrJo8g740HhokISsRMRL2/z+e16u0i5TKSwlqPv3bG6YCzurld++oMj7MbNg Y6+AVfy3TQM5RPPptGKRQclXM3YcjKdCH0BEiwL/RbgXtdyMzR1TDZ+6nlVqAOJCfH6M Er8dRLzEmlWfoljxW1wyZCTlUEfGasBjgkh/Bpm/Xm3sBX37IZiO0WtJJTn6YzdPo5BT onstvdW/nlU2shjG4fGkoV2eL2eXL8bN+OeJMCRnsQAk75GDcgMkeFoptkCPWvm12vdY MwkL6JS8rQ0UFaUeeKT4odCinhmD+ePqTKUyNkJZD3g0HPCWiP56F+BippT908iWBq+Y G1OA== 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 s67-v6si279057pfd.288.2018.06.12.07.31.57; Tue, 12 Jun 2018 07:32:12 -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 S933408AbeFLObW (ORCPT + 99 others); Tue, 12 Jun 2018 10:31:22 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:46928 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754290AbeFLObV (ORCPT ); Tue, 12 Jun 2018 10:31:21 -0400 Received: (qmail 3104 invoked by uid 2102); 12 Jun 2018 10:31:20 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 12 Jun 2018 10:31:20 -0400 Date: Tue, 12 Jun 2018 10:31:20 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Zhouyang Jia cc: Greg Kroah-Hartman , , , Subject: Re: [PATCH] usb: storage: add error handling for kcalloc In-Reply-To: <1528707147-35623-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 Mon, 11 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 > --- > drivers/usb/storage/alauda.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c > index 900591d..c56355c 100644 > --- a/drivers/usb/storage/alauda.c > +++ b/drivers/usb/storage/alauda.c > @@ -437,6 +437,11 @@ 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)) { > + pr_warn("alauda_init_media: memory allocation failed\n"); > + return USB_STOR_TRANSPORT_ERROR; > + } pr_info() isn't a good routine to use here, because it doesn't print the device or driver name. In any case, a log message isn't necessary. kcalloc() will already put a message in the log if either of the allocations fails. Alan Stern > > if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) > return USB_STOR_TRANSPORT_ERROR; >