Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1950257imm; Thu, 14 Jun 2018 06:31:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJMb7snuf1ojcXsxBaHVLshwYQr0QTjaM9DCGqHv+7fBt/kSD8s9jEJf1pQMYDJNT4CZonX X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr3111688pli.314.1528983081551; Thu, 14 Jun 2018 06:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528983081; cv=none; d=google.com; s=arc-20160816; b=yNvglRzmKDRF25v7SGZiUwu/HPCt6y2zKPi3ck8h4yo32eO2xo2bjNwbNdi25TLHRi 39g8sOFo0HxwyVuZMfu24Lv17ICV9afE43LRVrb8wheQlMBAWKuhDw6zShTLyX6mdpC4 /QTyljIp039gvxG9m1HUxzYYUNYTq7QMlw+/Ktn7m6tt+wyggyY5JU9KqGw+wtq+aQvn tGJzsQrjT74eLw9YTgT0IjH5UQFNoGVejE3qWa3n39MPy/eGS6x0Y7uN9qZjLJGe9k6g tSMKbYHTnfNsdYuC666ssQNPmxIJ9v8oI6AQKZLw0ChwZ03+UKi8UNLT5IRM2YAvStD+ fKVg== 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=Gk9vpMA1JXKxTPhEHh5XR6BLUoW/9jt7Va47frd5DNI=; b=HP6eQCYAEag6/0QdVU++6Ro8kj4uJb5iilkr3Ylb/lfXn+jv86DfBcRbx79DE93Hy6 27e9mFHcsh0hK5YdiGre4gfoM2mFv4J8OLkksXj14WaSl21Fz8qcwLDdeUDaN/UbtE0v 2LUtt3xqhjkLab6xTzlzSo9V7GZ/rglZQcLoHqMFzfUNOacqcpuOuNzqIOFV8oOFvwCH f9fCTqoMwHNKzdEx0aUthzvTPNz1sGBgGibFq2KV/WiU5ZK8E/53bWMAkgnHzLkKIP7L c6Xu/yZ+8u8zsVq1mJuyf4I84CAQMlVzaEy3TA9AY+qcwfYUmzuCdsx7vdY3bPoHzy73 rdaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tVQghfqs; 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 t8-v6si4494802pgq.369.2018.06.14.06.31.07; Thu, 14 Jun 2018 06:31:21 -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=tVQghfqs; 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 S1755305AbeFNN3U (ORCPT + 99 others); Thu, 14 Jun 2018 09:29:20 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:36787 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755252AbeFNN3R (ORCPT ); Thu, 14 Jun 2018 09:29:17 -0400 Received: by mail-pl0-f67.google.com with SMTP id a7-v6so3563945plp.3; Thu, 14 Jun 2018 06:29:16 -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=Gk9vpMA1JXKxTPhEHh5XR6BLUoW/9jt7Va47frd5DNI=; b=tVQghfqs/6FWjU4ecjCFSmWb2yLRB44UAm6RsIcCG1fkNSoSwyRbxxtVTJhrC4VMUk gqjIgltWtiE20BXlaRVdRaqGwmG0E0dv2RY1ZqXSMA1wUfpTWLlM2GvrvaZmhpM5/sKp 8qDqRw+Gi7iTx3JHSi/3QhT3x5Ojf+oq3m+gHASRH27Xwp+jMWdTo2byyt3+MqqBsF8b LmeueVrwkooXLvEAPbuXtmmrTadK8NppT2elMpygDMi3zPXG5128NrXD7KNeCCyKYTNA NEVkyWxBi7qW7J42P086E2HG0SH5guJ3yAz1wc6IltAlycCsXwznZomCseFby9MPjC2t 4qnQ== 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=Gk9vpMA1JXKxTPhEHh5XR6BLUoW/9jt7Va47frd5DNI=; b=h4ySJUrHEtk0Tuitr/KfARJCkIA3Uha5rUpV4giF69bIl0OmNZsbxaUOJv7U0mxiLs cu7JvXggwM7V2+Xk5f9pi0SQkkBQ82Rv84DMZYuJvPnnseYGuQXCh5MlSYJosqvY8/85 O6YaWtzEIH7Ol7Wt6pSh6TEjine/9bE7Bqwp2l1v2gzujUCnUgqAdoZS6acTMvtqEP9A MUPkX+0Hdj18lTqVIkF15m/EFplkDl/+oLcxZVMQD9VvuDui56GzJ6k0KVvN0ZwMVBhv 7LijDkTAJ3EzgOrzzeT3xAbXnUuh8KxFUuuMhGPEEC1FO39FhU4HC7ytphl8fd6KsycW lsSw== X-Gm-Message-State: APt69E3DrZXuqucTMQ2GKh7gfN+sRZtOEhBRHao01oe8uq8rAGW0umIh oMN0MJgKjltzgxVSbEtbNkE= X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr3005731pln.197.1528982956606; Thu, 14 Jun 2018 06:29:16 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id t23-v6sm11041342pfa.86.2018.06.14.06.29.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 06:29:15 -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 v2] usb: storage: add error handling for kcalloc Date: Thu, 14 Jun 2018 21:29:11 +0800 Message-Id: <1528982951-52753-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528707147-35623-1-git-send-email-jiazhouyang09@gmail.com> References: <1528707147-35623-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 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; -- 2.7.4