From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C4C1E95A91 for ; Mon, 9 Oct 2023 13:14:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376857AbjJINON (ORCPT ); Mon, 9 Oct 2023 09:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377010AbjJINN7 (ORCPT ); Mon, 9 Oct 2023 09:13:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0A56EA for ; Mon, 9 Oct 2023 06:13:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8F6BC433C8; Mon, 9 Oct 2023 13:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1696857237; bh=Mozk1Mkd7jmKck3IZ1qOP30vxv9hdk+4sLmB6JX12HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OoWXZOUQqww68viuDGUtaMyCE7123h255XmESHQ6Wpmz2NyaZ9koMYyLOLV64IQvo +107p4wlAVZVG/TdYB8PjZquZWT3kqIkiag7+G1jsjUi+7M5WXb24bx+hIpG2NiHfC uiJ7QX3tCDyHFt4PbMKPmFkn6dP95I8Kf8o8mkQc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, kernel test robot , Dan Carpenter , Geert Uytterhoeven , Rob Herring Subject: [PATCH 6.5 142/163] of: dynamic: Fix potential memory leak in of_changeset_action() Date: Mon, 9 Oct 2023 15:01:46 +0200 Message-ID: <20231009130127.963252606@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231009130124.021290599@linuxfoundation.org> References: <20231009130124.021290599@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 6.5-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter commit 55e95bfccf6db8d26a66c46e1de50d53c59a6774 upstream. Smatch complains that the error path where "action" is invalid leaks the "ce" allocation: drivers/of/dynamic.c:935 of_changeset_action() warn: possible memory leak of 'ce' Fix this by doing the validation before the allocation. Note that there is not any actual problem with upstream kernels. All callers of of_changeset_action() are static inlines with fixed action values. Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ Signed-off-by: Dan Carpenter Reviewed-by: Geert Uytterhoeven Link: https://lore.kernel.org/r/7dfaf999-30ad-491c-9615-fb1138db121c@moroto.mountain Signed-off-by: Rob Herring Signed-off-by: Greg Kroah-Hartman --- drivers/of/dynamic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -927,13 +927,13 @@ int of_changeset_action(struct of_change { struct of_changeset_entry *ce; + if (WARN_ON(action >= ARRAY_SIZE(action_names))) + return -EINVAL; + ce = kzalloc(sizeof(*ce), GFP_KERNEL); if (!ce) return -ENOMEM; - if (WARN_ON(action >= ARRAY_SIZE(action_names))) - return -EINVAL; - /* get a reference to the node */ ce->action = action; ce->np = of_node_get(np);