Message ID | 20230306160016.4459-39-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 v21csp1923756wrd; Mon, 6 Mar 2023 08:04:48 -0800 (PST) X-Google-Smtp-Source: AK7set/jujZWGMOPbDuep8yhLpzbNG/WaidysKelq5sRVLtzuTnxkoHgq8x8gj0RmESOd8i4CACs X-Received: by 2002:aa7:df93:0:b0:4ab:5ce9:9f83 with SMTP id b19-20020aa7df93000000b004ab5ce99f83mr11208621edy.23.1678118688568; Mon, 06 Mar 2023 08:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678118688; cv=none; d=google.com; s=arc-20160816; b=pH6+fbqgrCzw2BQlENryY18WNC7HEzAcMaqq7AG0bQeAXAoBoj5MDaJROuhffkAqtw KbOYr1Uif1xnsLobX2PYO6QJv4zl6ONzc4vOYWVKXTpUJCiXTbr3hyFpg7rkjoAHGtBe 6v+CrV8x3tsdMOv6VZQw9w6SMkl0Y5RZa8Xu3UN6G1+z/TRFbWjuPrk+JSgnd4MKoxGv 8Qvw8lSRTTdaIZWZedPKx7Anv6D5J+dSvOSobQRXpW8NkgbtL9tHH9gmAkxORxcuMRTI 96+qJmCwRrvuhv9xl11V0/C/9QABFhYWaP6lapL1NTVyfDBJ38i1VH7M7a/t8HzX1t9e +eEg== 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=0mI5hxY6oQ2Q0qWcdERaw/gENN4eL71qVG14XGIWDCI=; b=EgG5DgPe/2hvAAv9RCyliF5TUA0PNhWmRvH9Z/hKoYY/Hf71yAnGllEGpIX8SdUBjN POTSfazwfVmT95S1dIBsB1kUCaMiRyjtsI7GSygTq2p/5jIkmprWm3d4a1TgBqhyO/Pd wDF7L0Ed0Wgqw6BPM3a0U3dSnPdHg0TumCEuFyKcFo14gbKAn0Hlw9RI1chdQCtditXl /rN2+nE5U3zXhgo4GRScZ/nFZ7xxUpOkPzpcb376IfH2+3Eb1qYqnsxVSGb+Ae6HB4Zt RTE0d/0IgUYL7uXqhcRL7E2OHKoEwhSqip+u4+a+/AwQLNFRxlS5GouNbvnrHOFkVvhF cujw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=YDxqQDsM; dkim=neutral (no key) header.i=@suse.de header.b=G5QYY12i; 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 f6-20020aa7d846000000b004bf4b5c1d5esi10592715eds.200.2023.03.06.08.04.21; Mon, 06 Mar 2023 08:04:48 -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=YDxqQDsM; dkim=neutral (no key) header.i=@suse.de header.b=G5QYY12i; 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 S230384AbjCFQDE (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 6 Mar 2023 11:03:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjCFQAl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Mar 2023 11:00:41 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C232FCFD; Mon, 6 Mar 2023 08:00:40 -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 C62271FE6A; Mon, 6 Mar 2023 16:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678118438; 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=0mI5hxY6oQ2Q0qWcdERaw/gENN4eL71qVG14XGIWDCI=; b=YDxqQDsMAp2UjoBTYs3dheGgn2s0QrRmSahZQmc9b99QUFQtkLLjYzwCOza3atJg8P3qNH w0p6UElS0n3VFUx3Qw0xcRTINa4XFbhhnSkOQbG15WBIJN6z3330ZLNnhx1PQfov3Csx+Y QIC3KuEFK1l+ee/LUE9ck4iOV+mqMRA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678118438; 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=0mI5hxY6oQ2Q0qWcdERaw/gENN4eL71qVG14XGIWDCI=; b=G5QYY12iSeLUPhHPCh0//gAizWQw49VWoI4CZAvAG0KKVWPuNaDPYGe5vDkb9S29FvhGE9 mPj6MjKM7bBIv6CQ== 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 68A7613A6A; Mon, 6 Mar 2023 16:00:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OO23GCYOBmQ/PwAAMHmgww (envelope-from <tzimmermann@suse.de>); Mon, 06 Mar 2023 16:00:38 +0000 From: Thomas Zimmermann <tzimmermann@suse.de> To: deller@gmx.de, paulus@samba.org, benh@kernel.crashing.org, linux@armlinux.org.uk, pjones@redhat.com, timur@kernel.org, adaplas@gmail.com, s.hauer@pengutronix.de, shawnguo@kernel.org, mbroemme@libmpq.org, thomas@winischhofer.net, James.Bottomley@HansenPartnership.com, spock@gentoo.org, sudipm.mukherjee@gmail.com, teddy.wang@siliconmotion.com, geert+renesas@glider.be, 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 38/99] fbdev/intelfb: Parse option string with struct option_iter Date: Mon, 6 Mar 2023 16:59:15 +0100 Message-Id: <20230306160016.4459-39-tzimmermann@suse.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306160016.4459-1-tzimmermann@suse.de> References: <20230306160016.4459-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?1759634982049475711?= X-GMAIL-MSGID: =?utf-8?q?1759634982049475711?= |
Series |
fbdev: Fix memory leak in option parsing
|
|
Commit Message
Thomas Zimmermann
March 6, 2023, 3:59 p.m. UTC
Use struct option_iter to walk over the individual options in the
driver's option string. Replaces the hand-written strsep() loop with
a clean interface. The helpers for struct option_iter handle empty
option strings and empty options transparently. The struct's _init
and _release functions duplicate and release the option string's
memory buffer as needed.
Done in preparation of constifying the option string.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/video/fbdev/intelfb/intelfbdrv.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c index 896c2646e2ae..2d4e03b9e7fd 100644 --- a/drivers/video/fbdev/intelfb/intelfbdrv.c +++ b/drivers/video/fbdev/intelfb/intelfbdrv.c @@ -108,6 +108,7 @@ */ #include <linux/aperture.h> +#include <linux/cmdline.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> @@ -323,9 +324,10 @@ static __inline__ int get_opt_bool(const char *this_opt, const char *name, return 1; } -static int __init intelfb_setup(char *options) +static int __init intelfb_setup(const char *options) { - char *this_opt; + struct option_iter iter; + const char *this_opt; DBG_MSG("intelfb_setup\n"); @@ -348,9 +350,9 @@ static int __init intelfb_setup(char *options) * video=intelfb:1024x768-16@75,accel=0 */ - while ((this_opt = strsep(&options, ","))) { - if (!*this_opt) - continue; + option_iter_init(&iter, options); + + while (option_iter_next(&iter, this_opt)) { if (get_opt_bool(this_opt, "accel", &accel)) ; else if (get_opt_int(this_opt, "vram", &vram)) @@ -378,6 +380,8 @@ static int __init intelfb_setup(char *options) } } + option_iter_release(&iter); + return 0; }