Message ID | 20230309160201.5163-99-tzimmermann@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp399289wrd; Thu, 9 Mar 2023 08:55:25 -0800 (PST) X-Google-Smtp-Source: AK7set8vWVxkLsv8xYqWdJL9ovfG3EIcGH5VqbKMoFrBLmWk5KLLwdpQF7PDJyXYULvqrJnvGRUq X-Received: by 2002:a17:903:24d:b0:19e:76b7:c7d2 with SMTP id j13-20020a170903024d00b0019e76b7c7d2mr26103086plh.26.1678380925133; Thu, 09 Mar 2023 08:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678380925; cv=none; d=google.com; s=arc-20160816; b=0/pV/KP6AZyfWaL5Dfqma9Dj78m51uIPXKCeTL0LRge97k4zR458u9MeE5ipVQroAp r6zQwrtYHFvxucP5pdBJ3DDVZxo92Hl1UvNxhe7XiZb0JUUqZltAOs9oYsrK6ipDNeay YPT2+vTLhxpQCZGq/kD45qM3u4vnHQTyK7ZfvACwiHDeJ1ynFZpB5EwGP9o0aZ9Uixz7 RSGMeGHWiUSbV6SeCGyIK2ig5LC11SFj2QjlCqi1k0HAvQH1UxlSSprVm2g+1P1wOnou cmpKWe2ZzWdTZ0McbHIjwJ9hKY53f6ETf+vtz+wp/PvCI0+xmYuj3LQlFrM+SeXe+bxG RpwQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=qhLabhC1FIHHBl6vHn75Sdi6c+0lehlO1hOW2wnnzIk=; b=g3oxY1/el2qsC13qZBrTZHqrsIz4w2NWyspoxgq5YiN/UpBaERO+K411VKLqaiHaha lQM4FJhrhU8C1oFF9YZmK6JxrHZN4x6MrI70+HbaZukrFc+C0Hnho0upb2L5XkLbW90Y O3s8lzdLgd4tozVw0AubL9x8sgdGn/r+NLJfd3IqGo5mWsvgtn+YkxpXCC4zvxviZrba qp9DzqPKhgkEfhZe8avyVHG1V7h89hyt8fHyhBMStd/Jvea6p/zUifxiLRk8GzDQrp3X pr/SUYMPI1irwB+LOgLxXJpp5SNUK0NzRmZD+WOwjDCuMDX4y/o7L9ByHSPOhqivqmvX dIyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=nLLiHnJy; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la11-20020a170902fa0b00b0019ccdd9d745si16663396plb.17.2023.03.09.08.55.08; Thu, 09 Mar 2023 08:55:25 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=nLLiHnJy; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbjCIQLN (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Thu, 9 Mar 2023 11:11:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231796AbjCIQDE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Mar 2023 11:03:04 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE631F8F0B; Thu, 9 Mar 2023 08:02:45 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 577792019D; Thu, 9 Mar 2023 16:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678377764; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qhLabhC1FIHHBl6vHn75Sdi6c+0lehlO1hOW2wnnzIk=; b=nLLiHnJyAkWEMzDS6gjlT7FAdHKqeDNCtYCIowjWNGDofjK1AIIxp8zGGtJcR/KkquSxDT PVrA32O9RAps2X653Z/8p6kX3gRKcE67DEmuX4qka13Y+AmhcKSVcHi/p1ACdn2OXJN8x/ DTPilzT4nPENL7eMgxCCo7c4CL9/Pj0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678377764; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qhLabhC1FIHHBl6vHn75Sdi6c+0lehlO1hOW2wnnzIk=; b=KoO3w/NPCYL06ZUt0wLOVphV7yy1GS9O2qp8D5I5nJAWbw9LROqi6LRRuxmQXywwjAWvyJ xXny5w07zN9e80Bw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EA5F81391B; Thu, 9 Mar 2023 16:02:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4M1LOCMDCmQHbgAAMHmgww (envelope-from <tzimmermann@suse.de>); Thu, 09 Mar 2023 16:02:43 +0000 From: Thomas Zimmermann <tzimmermann@suse.de> To: deller@gmx.de, geert+renesas@glider.be, timur@kernel.org, rdunlap@infradead.org, paulus@samba.org, benh@kernel.crashing.org, linux@armlinux.org.uk, pjones@redhat.com, adaplas@gmail.com, s.hauer@pengutronix.de, shawnguo@kernel.org, mbroemme@libmpq.org, thomas@winischhofer.net, James.Bottomley@HansenPartnership.com, sudipm.mukherjee@gmail.com, teddy.wang@siliconmotion.com, corbet@lwn.net Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Thomas Zimmermann <tzimmermann@suse.de> Subject: [PATCH v2 098/101] staging/sm750fb: Release g_settings in module-exit function Date: Thu, 9 Mar 2023 17:01:58 +0100 Message-Id: <20230309160201.5163-99-tzimmermann@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309160201.5163-1-tzimmermann@suse.de> References: <20230309160201.5163-1-tzimmermann@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759909956875996359?= X-GMAIL-MSGID: =?utf-8?q?1759909956875996359?= |
Series |
fbdev: Fix memory leak in option parsing
|
|
Commit Message
Thomas Zimmermann
March 9, 2023, 4:01 p.m. UTC
Free g_settings in module-exit function for symmetry with its
allocation in module-init function. Fixes a possible undefined
dereference of the pointer.
The string g_settings is initialized ifrom within the module-init
function lynxfb_init() and used from within the PCI probe function.
It is later freed in the PCI device's remove function. Probing another
PCI device afterwards accesses g_settings in an undefined state.
Fix this by freeing g_settings in lynxfb_exit(). Also streamline the
code that creates g_settings in the first place.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/staging/sm750fb/sm750.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index effc7fcc3703..fa8ae20bb688 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -1093,13 +1093,12 @@ static void lynxfb_pci_remove(struct pci_dev *pdev) iounmap(sm750_dev->pvReg); iounmap(sm750_dev->pvMem); - kfree(g_settings); } static int __init lynxfb_setup(char *options) { - int len; - char *opt, *tmp; + size_t len; + char *opt, *outbuf; if (!options || !*options) { pr_warn("no options.\n"); @@ -1109,11 +1108,10 @@ static int __init lynxfb_setup(char *options) pr_info("options:%s\n", options); len = strlen(options) + 1; - g_settings = kzalloc(len, GFP_KERNEL); - if (!g_settings) + outbuf = kzalloc(len, GFP_KERNEL); + if (!outbuf) return -ENOMEM; - - tmp = g_settings; + g_settings = outbuf; /* * Notes: @@ -1133,12 +1131,11 @@ static int __init lynxfb_setup(char *options) } else if (!strncmp(opt, "dual", strlen("dual"))) { g_dualview = 1; } else { - strcat(tmp, opt); - tmp += strlen(opt); - if (options) - *tmp++ = ':'; - else - *tmp++ = 0; + if (outbuf != g_settings) + *outbuf++ = ':'; // add separator + len = strlen(opt); + memcpy(outbuf, opt, len); + outbuf += len; } } @@ -1186,6 +1183,7 @@ module_init(lynxfb_init); static void __exit lynxfb_exit(void) { pci_unregister_driver(&lynxfb_driver); + kfree(g_settings); } module_exit(lynxfb_exit);