From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79AE924A04F; Tue, 20 May 2025 14:12:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747750359; cv=none; b=eoLokODOwNjAviUnXQ6y5kV5KftYhFfTrt9N6mKdYGUa8Vxr0DuLlj6hm7tkzf0TTp3T0NvwdBIBAtrc1Nj0Sp2xt2ogw9x0ZUPgmZMxv/ZnuO16JhWYih7mFD3a0mYCh0aAe/CCNHT4IjTP+rNmiDI9GNzjv6NhESmNkDXHRxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747750359; c=relaxed/simple; bh=d98JhYspnEoyzIcoFpP+1HCb9Rx/FM3TSe+oQAMGo7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OtJy2H/qwpvTjy4SJ8plHPH6+3+3oRuDEnlaESdWWAFs9lRJ6VsqXA9N2EFpAlC8oPY+5hVLV3vXmNaF4Ji319bi0drDqx5pIBrqGciExG865GDBBQZhrfk5wvbs7EER0iFAcPEebyA6C4VqZRZoOZnXHvuTOkyoXCT9Loc4Ch8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=s2TakDMb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="s2TakDMb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E594BC4CEE9; Tue, 20 May 2025 14:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1747750359; bh=d98JhYspnEoyzIcoFpP+1HCb9Rx/FM3TSe+oQAMGo7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s2TakDMb0SjaeAlwnyUiiQAWFYF5UbzgRp6VoBMwU/Q6SqsYW+WR5MBrmJyb2t01h 4qkhZq8ywEQtriGqM9vG7T4aw47FsIl4jmZUvOccYwxF/umXs/3VsVWpd/pc9ReJRh IUFn2yyEbKBGjFiKum5Ua8dygo5SvgvIKr1or6c8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuai Xue , Dave Jiang , Fenghua Yu , Vinod Koul Subject: [PATCH 6.12 126/143] dmaengine: idxd: fix memory leak in error handling path of idxd_alloc Date: Tue, 20 May 2025 15:51:21 +0200 Message-ID: <20250520125814.979896438@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250520125810.036375422@linuxfoundation.org> References: <20250520125810.036375422@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuai Xue commit 46a5cca76c76c86063000a12936f8e7875295838 upstream. Memory allocated for idxd is not freed if an error occurs during idxd_alloc(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: a8563a33a5e2 ("dmanegine: idxd: reformat opcap output to match bitmap_parse() input") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu Link: https://lore.kernel.org/r/20250404120217.48772-7-xueshuai@linux.alibaba.com Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/idxd/init.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -602,28 +602,34 @@ static struct idxd_device *idxd_alloc(st idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type); idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); if (idxd->id < 0) - return NULL; + goto err_ida; idxd->opcap_bmap = bitmap_zalloc_node(IDXD_MAX_OPCAP_BITS, GFP_KERNEL, dev_to_node(dev)); - if (!idxd->opcap_bmap) { - ida_free(&idxd_ida, idxd->id); - return NULL; - } + if (!idxd->opcap_bmap) + goto err_opcap; device_initialize(conf_dev); conf_dev->parent = dev; conf_dev->bus = &dsa_bus_type; conf_dev->type = idxd->data->dev_type; rc = dev_set_name(conf_dev, "%s%d", idxd->data->name_prefix, idxd->id); - if (rc < 0) { - put_device(conf_dev); - return NULL; - } + if (rc < 0) + goto err_name; spin_lock_init(&idxd->dev_lock); spin_lock_init(&idxd->cmd_lock); return idxd; + +err_name: + put_device(conf_dev); + bitmap_free(idxd->opcap_bmap); +err_opcap: + ida_free(&idxd_ida, idxd->id); +err_ida: + kfree(idxd); + + return NULL; } static int idxd_enable_system_pasid(struct idxd_device *idxd)