Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3801786imm; Mon, 11 Jun 2018 01:54:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJVuOoAmIAJxlcGG0YXMmnE9kBVFBuetu960vKiukGXfJCmZmR26E1XIHRlNC5RMfVPMwdi X-Received: by 2002:a65:4a92:: with SMTP id b18-v6mr310068pgu.107.1528707270319; Mon, 11 Jun 2018 01:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528707270; cv=none; d=google.com; s=arc-20160816; b=fTnu3+sjIT8NJN4fhrOEtutoGEFj55RVUQ8GW8v49KTuioNHpluG31EOZBKYwy/vul zIWpRIcvath2N0lT2yWCQ7JN+wHKAjrgp/nQvlSXtO1xx8LV19CZ4ML/VahI98DQANy+ uaGKMwStgw7UQnIJeIPLYqwDagnLUFhl57uGZUhXShkpb/is3FMu/II2W/tQJFkqhXYH D78mpcePqpfhRxwL5lg9gAAwD8M6m8Iqk9mlfPh+yoIGhYHgjEi16u41YqvMjiQjX4VP pklMHO1MKREehw78CtWthOZRpai58D7MdPJ/zQRE5pTdfkRSXI2iuvRzlRe77XpdN6gr YZtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature:arc-authentication-results; bh=cmCEKRLCAHwV9KostSrIThoAzGLeQHJXtToj8bM7bsE=; b=aig6NQRC5kAWWnKpMdj5gQiBG+oH3IZhGEDgz95ixNf+7Px30KXR+2rykOtuVmhWOD rH6biCYyeLpPvB2qVDJ7C/sBQUD5UsNFmK7Cy+f3cih+RSrRuU3YjbCjyQ0VlCOiAd2y 9ugEcdeekiaGb2hNv7IMf9KNp2VlhtgFrJaoEcj6kZC7wHVPE8wLGq367CnLqHkYX1oT BDBL3LpBgzCH6Nm0304Ru0KjVEUW6/EmqQWAiKazPafYg8Rh0pYG5/Brc9QNcvBzDFGU WkwgVCza4uJOYhphprctc/bBGlXpifBpayisc0UizbTocQptMgXZ6IciYwpWUiSNOkvt 0h6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VOtKTTIi; 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 p187-v6si4646790pfp.125.2018.06.11.01.54.16; Mon, 11 Jun 2018 01:54:30 -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=VOtKTTIi; 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 S932536AbeFKIwg (ORCPT + 99 others); Mon, 11 Jun 2018 04:52:36 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34196 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932288AbeFKIwf (ORCPT ); Mon, 11 Jun 2018 04:52:35 -0400 Received: by mail-pg0-f66.google.com with SMTP id q4-v6so8361649pgr.1; Mon, 11 Jun 2018 01:52:34 -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; bh=cmCEKRLCAHwV9KostSrIThoAzGLeQHJXtToj8bM7bsE=; b=VOtKTTIiWpc2utmXPXLodkJUE0bQ7p8Erctgcl8mx7HWI9T79ovaJQIFJG+1Ld7+Dy opNFZDKFb8NUqnRACQTHfGROnHqUn9wUoHcvImnov26TCAJdtk0iXZL/7ulYo7ckXM5C FANNy1Fe/VRwsx7zJ1m+XexA7QIOd0CsrvjkYph9u3xn+LgA+esk9KBuOXite7ZdoIh4 asMD6S1TRStx26BqfG90HHGko9ZVUoGg704EyYi1GPMd0DJ6aRBpHbWAbRI7wrhnaB6A /35yJSw8AbSwoyFXW8aZKZLw54QmoqMKES0oLmUFETWiesMLwe1oOVbCM6NgJK8+S9fV fKvQ== 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; bh=cmCEKRLCAHwV9KostSrIThoAzGLeQHJXtToj8bM7bsE=; b=DdwxR+OhBvtSbN8ClQ9kyGGUsl0kpUKyi66TaN2sCTnCjJru9S+VKlKvhU70Vx5jyd JWCFCmg5N/R3Ahl4AXgli7gm+AjQuZbeFygxtTKJIGJByIA8m8+QPLSkdsKeP2XJCR1m QserZ2//8L92yK4uopMH3xFlh5ALf8abMXbtgfSJq+uJEP3XgKb8mqr2L4VRIad31wJg aui0GQM2F+aYptiv3Ki3YTOicplVnC8GNXpBbmIJN6VMfyq2hV6i44zm3t3qV74O4/4f TIpnjWmIMuzOGxJp+Q3RKW08l+prjSY2Elj0X9GM/pP6nslJJJXoGB1Ldylc+CdoOLPI wH2g== X-Gm-Message-State: APt69E3BpbwbZoF/chJ8oH1H5+x6izLpAmzFECAH0eWs1GoCf7Dd5hph ygc+WfeGEo2ckg1aPdkriac= X-Received: by 2002:a63:7001:: with SMTP id l1-v6mr14340350pgc.358.1528707154644; Mon, 11 Jun 2018 01:52:34 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id a14-v6sm29937731pgv.4.2018.06.11.01.52.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 01:52:34 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Alan Stern , Greg Kroah-Hartman , linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org Subject: [PATCH] usb: storage: add error handling for kcalloc Date: Mon, 11 Jun 2018 16:52:26 +0800 Message-Id: <1528707147-35623-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 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 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; + } if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) return USB_STOR_TRANSPORT_ERROR; -- 2.7.4