Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2916156rwb; Mon, 15 Aug 2022 14:00:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR53DasIdEIQIW+QPIq1XAsqrB3D6ZBHO55Ab+ejv+aorU4ocuQx84AGsbC4KqPajkmryHPU X-Received: by 2002:a17:906:8450:b0:730:6e9f:87bd with SMTP id e16-20020a170906845000b007306e9f87bdmr11811795ejy.615.1660597254475; Mon, 15 Aug 2022 14:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597254; cv=none; d=google.com; s=arc-20160816; b=dXM6DZVMoCF7H6mRNkGLjjAyjPcOmMbNgzlnK5nCbufESn55OkrnC0wz3dRTR5SKWK rLW20fgQT17II7YchA68jjr53of8ROvrL/5mInDFqNKBNngBN9gZWXnojEBhMe2nIKO+ 8+qk8pOr1ZCK6OsZgEl0Ud3x4kDBGVXL/GxbqwCevwgMAbtg8CFEwbBkDOx01krRKie2 FqKcW4ERQaIWaPRJuttav0bMfIhn1m4BRkdjzzQDU8+GANrD+mtedNh2JhE41jP+j9Lz B++65GfQGTJwYpVDoaMegozdL4XWA1KQbBc4h9lxerI/b5VrR+uhNSR6FDtbK9K14dF/ el7Q== 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=7Ur2J1/icBHv6PK57dle6tdAPlCppHiFyHVoMBErBpw=; b=DJy8cO3g9VbsYQuFrPEcjz5TNyDVQTKwXa22IXL88Jgv0u6uNoDBSrtTqnFSzVOa6g yFLDvg2ks6qyCmPxCSoD6KQrKtNpD1FH1O0YjeMhGYzAd6lhQo9fPnef90bkYt7l5iPV 1L8OKAZkRorcRbQKXBLgYadAFOp5t3qolDKCsRPo1Y1/uIaOoi7dIwqSV96pD74+d4UD OfHeoeIAfShNZACuu4c8xT4NhedYmgpoh4aFqJgbzlw4uHwTD+mdHHVtB2cjcoA4MBv+ n4+FiE4HJlI+7rhbErG3HqE18amIe/v3RpgvFV1n+AAtgk+P1DMhKVl8pdpgh3uywl3c pLiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gU+awE9M; 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 n12-20020a05640205cc00b00442edebe687si10112822edx.633.2022.08.15.14.00.28; Mon, 15 Aug 2022 14:00:54 -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=gU+awE9M; 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 S1344050AbiHOTTF (ORCPT + 99 others); Mon, 15 Aug 2022 15:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344337AbiHOTQ0 (ORCPT ); Mon, 15 Aug 2022 15:16:26 -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 65EE252E52; Mon, 15 Aug 2022 11:37:59 -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 678B961024; Mon, 15 Aug 2022 18:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58657C433C1; Mon, 15 Aug 2022 18:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588675; bh=4Y9obJ3d9SzWV7e3qd/6vTgE2ysm+GKbDTXk7kI8D4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gU+awE9MwapkVU0fJUiGdlf+m0e6faptFX3YLpwCwQ640DHO59BteMe3zyZlDQFCC BCrOYhzlO9zhHxLY6SdOpuRxPIMN6CcCHwH0wTs2v/kfYbf3zNhbUFW0GD6Dd5Alrf GNdd+tUahAOS0laR74LTBYPgP1h5vapJHIXgH7VI= 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 5.15 479/779] memstick/ms_block: Fix some incorrect memory allocation Date: Mon, 15 Aug 2022 20:02:03 +0200 Message-Id: <20220815180357.742528393@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 487e4cc2951e..7275217e485e 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -1341,17 +1341,17 @@ 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_array(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; } @@ -1962,7 +1962,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