Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3017755rwb; Mon, 15 Aug 2022 16:14:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR50oCevAWVJwz9hDnNyeQ2NyH1QvZeBQ7A/yK6EMYXq/u+XsDRSdfRpdxq6uUFPwTfv4Il9 X-Received: by 2002:a17:907:284a:b0:731:5a2f:655a with SMTP id el10-20020a170907284a00b007315a2f655amr11425839ejc.403.1660605266622; Mon, 15 Aug 2022 16:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605266; cv=none; d=google.com; s=arc-20160816; b=pxX1qOaDGAHhtb5973gSmQXerk9G1dt0kJy8PL8oUIJIBk41yYUs5kuXu+e9JADLlP Drg/euMv/yKBYW/ozh29RHN+7C3UZtXDJd8OjTVwf+wt/ScATBRBbYBVb5037drCyatz ApgWFnHCY3H19AKXebtOeAuHRElMoWoMaZ5OY+sO72z+wM+vmvciM1EpnhwPHXDr31f3 KCqnkFw1miOOoOyFpi7u0Z4bKUp7Gl9n5QaLlr/dXEXN6dPvxK5ATYE91oB0M0XkuOyU A2lUya8IFFph6x7XBlbZgbYqWeaWY/mvwbObm2rGMLHjPXUzA4zwj+sV/wGYSJ3KbLtG wqoA== 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=7JbjLH7TvJTHdEGrnVNradmgWB2v90226BX4/UIDSvo=; b=mzWqImJnUNFFUj4XxrH7v7V240tjfmcgEWpvwF7oexq20T3JlD4QbATUoks+psz6dz sXq+9b/hK90i3gDUpetSmOakA/FNfYMVU10jyp1sPdC86TRrxwvFG+gDE0zTVtOMicVk 7Nz5Nxji9K8T1Su9lPPx4UxO7cNkz1S9F3bRZuiDdfZWfNxGvN3ZyaDiaw7bEOeH7lR4 6ulb/MGG5xcjIJsyEqa953ub5BM4xlLUtzzyqVFwIZYd4cJbFNIunF7X4WHtfb6uLCvu prOyeKNav82Qgmxg/YpmXwWl9yvAx3PJ4zlXuTccYPqxKeI8BUA2ceYWG0KIugeeKdMs /J6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X0mLnWk0; 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 l4-20020a170906794400b00711da52c6e4si9176414ejo.309.2022.08.15.16.14.01; Mon, 15 Aug 2022 16:14:26 -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=X0mLnWk0; 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 S244536AbiHOWEd (ORCPT + 99 others); Mon, 15 Aug 2022 18:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350086AbiHOWBv (ORCPT ); Mon, 15 Aug 2022 18:01:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C29112FB6; Mon, 15 Aug 2022 12:36:09 -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 ams.source.kernel.org (Postfix) with ESMTPS id A1511B81142; Mon, 15 Aug 2022 19:36:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7922FC433D6; Mon, 15 Aug 2022 19:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592162; bh=wp7hdPxu6ia6rtSa1iMl9K8eSmzVjZoytHNlJt9raVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X0mLnWk0iCnBUUVkqG+a4MXzt1XWF560H/sjVRhn2xog4CWUZEZ4GveteevGfjBN7 3lRnSNBc/WIDvHvzA76gDyUUa3K/gPZ5Y1u41pjt9glyATJV+tZZgSKvJejDJntm+j kFYe98+fDLSoTemx1boBqimW5aMRrl3hvDEM1ZwY= 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.18 0743/1095] memstick/ms_block: Fix some incorrect memory allocation Date: Mon, 15 Aug 2022 20:02:22 +0200 Message-Id: <20220815180500.110410011@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 3993bdd4b519..f8f151163667 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; } @@ -1946,7 +1946,7 @@ static DEFINE_MUTEX(msb_disk_lock); /* protects against races in open/release */ 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