From patchwork Fri Nov 4 12:27:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Qilong X-Patchwork-Id: 1699511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=33os=3e=vger.kernel.org=sparclinux-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N3frn3M32z23lQ for ; Fri, 4 Nov 2022 23:22:16 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4N3frk6KP4z4xGH for ; Fri, 4 Nov 2022 23:22:14 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4N3frk6GNvz4xHV; Fri, 4 Nov 2022 23:22:14 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4N3frg4C8Cz4xGH for ; Fri, 4 Nov 2022 23:22:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbiKDMWJ (ORCPT ); Fri, 4 Nov 2022 08:22:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbiKDMWI (ORCPT ); Fri, 4 Nov 2022 08:22:08 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE4762D1DD for ; Fri, 4 Nov 2022 05:22:06 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N3fn75pD5zJnTy; Fri, 4 Nov 2022 20:19:07 +0800 (CST) Received: from kwepemm600014.china.huawei.com (7.193.23.54) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 4 Nov 2022 20:22:03 +0800 Received: from huawei.com (10.90.53.225) by kwepemm600014.china.huawei.com (7.193.23.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 4 Nov 2022 20:22:03 +0800 From: Zhang Qilong To: , CC: Subject: [PATCH] sparc: Fix possible memleak in of_set_property Date: Fri, 4 Nov 2022 20:27:08 +0800 Message-ID: <20221104122708.15488-1-zhangqilong3@huawei.com> X-Mailer: git-send-email 2.26.0.106.g9fadedd MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600014.china.huawei.com (7.193.23.54) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: sparclinux@vger.kernel.org If we do not find the target property, this part of memory that allocated to new_val is not referenced by anyone. It can not be freed after of_set_property() returns, then it will be leaked. We fix the problem by freeing it when not found the target name of the property. Fixes: dfa76060be85 ("sparc: Create common area for OF device layer code.") Signed-off-by: Zhang Qilong --- arch/sparc/kernel/prom_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c index c9ec70888a39..c127a815db5e 100644 --- a/arch/sparc/kernel/prom_common.c +++ b/arch/sparc/kernel/prom_common.c @@ -91,6 +91,9 @@ int of_set_property(struct device_node *dp, const char *name, void *val, int len raw_spin_unlock_irqrestore(&devtree_lock, flags); mutex_unlock(&of_set_property_mutex); + if (err) + kfree(new_val); + /* XXX Upate procfs if necessary... */ return err;