Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3407767rwa; Tue, 23 Aug 2022 04:23:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR7SBIHfvcxiuc6yd/k3ZtyPNXXxU+2U3tbFeasQ1rkKsJxHH33WkfZ3vpIUC/thBB8G1Owo X-Received: by 2002:a05:6a00:1996:b0:52e:b0f7:8c67 with SMTP id d22-20020a056a00199600b0052eb0f78c67mr24702820pfl.20.1661253810988; Tue, 23 Aug 2022 04:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253810; cv=none; d=google.com; s=arc-20160816; b=mqRZgA3UPNHfCb3CtpaQjjOkV8TH/IJitzg/CR1BqMhQIWjgiwKXEGlo3e5OdXWY5U wxjI8/A4ZmOlCEplEA4fq2FUmTR1MER7ey8Nz4tMqm0i/QTB7N6BmcSZXkmwv0lGyoKN XUaWY7bQePPWAONfNubYn4Zvdm3ZMnyNwhoBLOasN0uDzTEMPnVYLl7EPFNY9vsLmoLw +2dNaRUzXijOflpc1UCKGDuKLEy6JDgt4siu0T9fJouFY5OD5rFQUq0vSSKJd1X5mJT1 Dmvj11BImFnwzI3OMwXZtFGmBPNpZsSnetublSPFBRwzHQIPyu9RIQugfskqBqRBGPvX 4/fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sJ512jtEcoTaS0hRt+fxD7M2LIPFDuYhd0b+KwABfCA=; b=OX7zIEZYoYvaGTkk+dsUCMr3/oCtSm482okoJoR1pIc9hxfBeofhRISDOZ7fyvyx76 xaoPyDThvXmO6cT1NukS96uB+NA6xbaaq0lBSqGbhAztEMSvUSit6BEL2oFA9hLeL/t0 oj7vA4/jAlPpzHk6L+6n0Ca+oimre0Maczk8/VgVJRdtoQXKtm9aJBVXl38RSvidBcCK KoZlv0x9UQ90tIyYGvUmbA7jlTNWrKSGC2vt/UsJ9B1UHaUKx6dFdl9C42JITGCzEP/5 GCnrfgg2NZ0J+4sSV8yO/bg6kqmxN3U4dHmCvh1CHHJ2t5yNDUqfauU0LQGuBpMm55Kc NINw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=luSQ5yix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a65464a000000b0041bc22f2e79si16147623pgr.6.2022.08.23.04.23.19; Tue, 23 Aug 2022 04:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=luSQ5yix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241344AbiHWJtO (ORCPT + 99 others); Tue, 23 Aug 2022 05:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352283AbiHWJqM (ORCPT ); Tue, 23 Aug 2022 05:46:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7673D75496; Tue, 23 Aug 2022 01:43:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7F9D2614E9; Tue, 23 Aug 2022 08:43:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 860AAC433C1; Tue, 23 Aug 2022 08:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244208; bh=6JrT9EI5+j/PauKm10M95FzvHCL4nLV18Z8dTnkMfVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=luSQ5yix12WrB4ll19g3qQg5KaA5G0zRmn/axTx6DshsvAK3dYID+YGllXq0DswHs NDgh/3CcyA8Lj/qP89bXQbV3tQjDdw61TlOZTaUdpyoq/5DRCsjDTsIoMP4yOJ8AH/ fydEV01/v/fbDkD0T7OHsnZ60iGuLUInlNx/h/qw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Ulf Hansson , Sasha Levin Subject: [PATCH 4.14 103/229] memstick/ms_block: Fix some incorrect memory allocation Date: Tue, 23 Aug 2022 10:24:24 +0200 Message-Id: <20220823080057.377765792@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit 2e531bc3e0d86362fcd8a577b3278d9ef3cc2ba0 ] Some functions of the bitmap API take advantage of the fact that a bitmap is an array of long. So, to make sure this assertion is correct, allocate bitmaps with bitmap_zalloc() instead of kzalloc()+hand-computed number of bytes. While at it, also use bitmap_free() instead of kfree() to keep the semantic. Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks") Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/dbf633c48c24ae6d95f852557e8d8b3bbdef65fe.1656155715.git.christophe.jaillet@wanadoo.fr Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/memstick/core/ms_block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index ffe875740671..7138062733ba 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -1338,16 +1338,16 @@ static int msb_ftl_initialize(struct msb_data *msb) msb->zone_count = msb->block_count / MS_BLOCKS_IN_ZONE; msb->logical_block_count = msb->zone_count * 496 - 2; - msb->used_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL); - msb->erased_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL); + msb->used_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL); + msb->erased_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL); msb->lba_to_pba_table = kmalloc(msb->logical_block_count * sizeof(u16), GFP_KERNEL); if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table || !msb->erased_blocks_bitmap) { - kfree(msb->used_blocks_bitmap); + bitmap_free(msb->used_blocks_bitmap); + bitmap_free(msb->erased_blocks_bitmap); kfree(msb->lba_to_pba_table); - kfree(msb->erased_blocks_bitmap); return -ENOMEM; } @@ -1960,7 +1960,7 @@ static int msb_bd_open(struct block_device *bdev, fmode_t mode) static void msb_data_clear(struct msb_data *msb) { kfree(msb->boot_page); - kfree(msb->used_blocks_bitmap); + bitmap_free(msb->used_blocks_bitmap); kfree(msb->lba_to_pba_table); kfree(msb->cache); msb->card = NULL; -- 2.35.1