Message ID | 20230309160201.5163-11-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 v21csp388207wrd; Thu, 9 Mar 2023 08:32:33 -0800 (PST) X-Google-Smtp-Source: AK7set8rgSuqa1jL+N4qNcL4h58MszY0pd+zl4/7uakMPGELgZOo6yzpRiPHazlRr1DKdfehS+xK X-Received: by 2002:a62:1a8d:0:b0:5dc:ecea:fc8b with SMTP id a135-20020a621a8d000000b005dceceafc8bmr17100403pfa.29.1678379553145; Thu, 09 Mar 2023 08:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678379553; cv=none; d=google.com; s=arc-20160816; b=KajLghM09wYpdsXjD672Tesc5iULH9Giz6rVjhzvZXI7Jtu0xWpNTQjFCTo9l044Ub zIqZ1QqamEaAE3w8rIXUEqDP1ED4iI6oigtxqCDhjxKKi7Icl1lVerd2kiihHO98nknE U9gssNeFZLtMpaEoeOR8FTK6zyg5Ef+DpuYWCHr7lzPrnN2LkRkBuDR7iZoGefCMxARx FrmBKKYuhRIEFBPbu+nTJwU9HxiLuFW4J0I4s1YAWFLyNX7HfpOf/q+yGxVHVZw5kScB F46RgNa231IBr3u6gOLZF2n4msBCUi2RxyMJpugSMvA3nZVRZ6jyyFLFreaR9hMY0t0t Uoag== 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=qPLL2nIMXVIbOX360ZiaSKuPOUXR3YFNZkhMEK9hl5o=; b=IBpMsAtKB40EHYPF5RVUjwM6PdOVJK4H2Wr2c8G+PyfGN6TPg7OnDV8qL43n4jTQi1 kZb8Gdkvjj0WvpMrpTWs6qqPBAW6obBLtOQtvAO2TZeAYvyeIzTAsmoXT8XgRJvqti8C 2UsVTD+t5IyL4yg4AX5A+mGOEke4pun5YJoGjuRyWDaooRqj6PB8eZdpmv8MY/pgXmyk lvHfVT8k6lGBPApGIvsn+FfP4GKm1FZdYT9vnuVIB7l/ywBIx6MutsQvdfXmmC409s0v MFUxAQiTXAdI63+rE046MtiiX2pXtYYPM+5YTAc6H6w+zwlxMsQFPama2QdNQEt9UFgo gDTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=trE7up6t; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 n11-20020aa7984b000000b005a8c6714ffesi17296400pfq.96.2023.03.09.08.32.20; Thu, 09 Mar 2023 08:32:33 -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=trE7up6t; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 S231822AbjCIQDP (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Thu, 9 Mar 2023 11:03:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbjCIQCL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Mar 2023 11:02:11 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFFDBF4B7A; Thu, 9 Mar 2023 08:02:09 -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-out1.suse.de (Postfix) with ESMTPS id 9D3A322149; Thu, 9 Mar 2023 16:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678377728; 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=qPLL2nIMXVIbOX360ZiaSKuPOUXR3YFNZkhMEK9hl5o=; b=trE7up6tmAL8SM9RbL+ai1E5Cq3JpkvyWTc+J3fidroMRDQ4e2RJKpFjXU01wCryg/ONIP 0L+NcJvqQG5Hn1WbN5zu84UJjaBmnQQkCs05aIy/CNGn7O+atljpOQJwrVG6VHd95Ymumq ZoUwZGockmE47KlNWpBdmfnQGfvVJ94= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678377728; 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=qPLL2nIMXVIbOX360ZiaSKuPOUXR3YFNZkhMEK9hl5o=; b=61DoR8i/KKWWcskabhK7cyMJ3KnsxiG6NbRhVV4D1pVyBP0r2ztvDjpLiMqUP5fBBZc5J/ qpDb4TCqn25oLIDg== 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 391291391B; Thu, 9 Mar 2023 16:02:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mB4KDQADCmQHbgAAMHmgww (envelope-from <tzimmermann@suse.de>); Thu, 09 Mar 2023 16:02:08 +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 010/101] fbdev/atafb: Parse option string with struct option_iter Date: Thu, 9 Mar 2023 17:00:30 +0100 Message-Id: <20230309160201.5163-11-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?1759908518404601573?= X-GMAIL-MSGID: =?utf-8?q?1759908518404601573?= |
Series |
fbdev: Fix memory leak in option parsing
|
|
Commit Message
Thomas Zimmermann
March 9, 2023, 4 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.
v2:
* add missing call to option_iter_init()
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/video/fbdev/atafb.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c index f0cc7c992c88..6e625ac020b5 100644 --- a/drivers/video/fbdev/atafb.c +++ b/drivers/video/fbdev/atafb.c @@ -47,6 +47,7 @@ #define ATAFB_EXT #define ATAFB_FALCON +#include <linux/cmdline.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> @@ -2934,17 +2935,15 @@ static void __init atafb_setup_user(char *spec) } } -static int __init atafb_setup(char *options, struct platform_device *pdev) +static int __init atafb_setup(const char *options, struct platform_device *pdev) { + struct option_iter iter; char *this_opt; int temp; - if (!options || !*options) - return 0; + option_iter_init(&iter, options); - while ((this_opt = strsep(&options, ",")) != NULL) { - if (!*this_opt) - continue; + while (option_iter_next(&iter, &this_opt)) { if ((temp = get_video_mode(this_opt))) { // ignore errors mode_option = devm_kstrdup(&pdev->dev, this_opt, GFP_KERNEL); @@ -2981,6 +2980,9 @@ static int __init atafb_setup(char *options, struct platform_device *pdev) else if (!strncmp(this_opt, "R", 1)) atafb_setup_user(this_opt + 1); } + + option_iter_release(&iter); + return 0; }