Message ID | 20230309160201.5163-66-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 v21csp380859wrd; Thu, 9 Mar 2023 08:18:05 -0800 (PST) X-Google-Smtp-Source: AK7set8c4lB2yCQm82zdJb5zNa/4gCyZafmXCI/rvP6Ja9ZqQeS6ohuDe/EZWW6SNfEEpwvqyDGQ X-Received: by 2002:a17:90b:1c88:b0:233:f98a:8513 with SMTP id oo8-20020a17090b1c8800b00233f98a8513mr24942807pjb.8.1678378685685; Thu, 09 Mar 2023 08:18:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678378685; cv=none; d=google.com; s=arc-20160816; b=aF3yVDIBnarL36gDtolLKfkdmSYIInCKE5AJIE29sn51Y6WFI7QaaEdMzHCIM9N3Y4 Lvv3LgbBynlyMjQ7IMSB5/fKrMw2dsUTPfoaV7nb/wfIyMObmr3KvU8Ek7SP2J/QXNDF DDPHeGeG9+Zat4jBAaWxf8k3tQC7VaHZ6+RtcY7ZJ6p0MsPPTFXpvC2ZzdulKC7loaHl tSi1OVUU6C3f7sFES6d7i8NNRejqceDXM/o3cjjaSPLtC7eQqlCHPt9B263mGWp/sRUc JvlCanddRrHT2Bz7VLgZqin1GIXjvq46eWU97NAUgZiSWuRTOmIJuijbwJg7cDQZeIkT n49Q== 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=i9kXMRzl84QLn/fJf6kdz3b+HhhBrJcv0BrlgL/PbEg=; b=RYMEs8GNc36VuyZ1mB86NxTehheAKDeOhCsxXhRQrV2XWiizoTh/Ew7JKXGcQFupnE fEcUoKumhcEGgry0YnRCKorvqdXmchs0Ow/hGW1S3XxhgDvdIUqT58DLVE/0ywmK4dfo 5ekJDeD+7NcQScBHcQp4rl2L3+NnA7rN4fdu8xODe5OJeKRwYMIbXnaJNn03hxMTW8YR E/CIaAopZJWnjs8AWzXhlhuwmU+mJXAA1eHTuBhLhul/AgyyDloyqYkLC/7MJX6MKf2y maNQsOF4n7+3wH1rsDOgcM0p7us3Yu7bMrYg8kuX/Z9aSRY8hHh5c0CcPZDDrY7bBKNc SpaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=lcW5jkLq; 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 f21-20020a63de15000000b004de7c3add77si16880892pgg.262.2023.03.09.08.17.52; Thu, 09 Mar 2023 08:18:05 -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=lcW5jkLq; 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 S232303AbjCIQHo (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Thu, 9 Mar 2023 11:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbjCIQCc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Mar 2023 11:02:32 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF96CF786F; Thu, 9 Mar 2023 08:02:31 -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 9D54C20192; Thu, 9 Mar 2023 16:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678377750; 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=i9kXMRzl84QLn/fJf6kdz3b+HhhBrJcv0BrlgL/PbEg=; b=lcW5jkLqcuR67+A4lDjPzUQmUXrC1v0MNNCKRJEl+PUF2DjZ1Z5p8aI59In8NRD2grpFi8 L3x+183urkgRk2mUMZ2d/Vofzua7YVUSrMEXHIVzMj1wN8mGAsbqxI4v+XDe2zjM2URfb9 e0zsFsbXMNLaAJJ9tkn/YHbBj961978= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678377750; 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=i9kXMRzl84QLn/fJf6kdz3b+HhhBrJcv0BrlgL/PbEg=; b=3He5Ygju0enbSqJS3GobyTos5rFr008eOHgqKgbqqs3295oCQSSiLg15pj8L5QjzPxotmw AMejKys/mzYKzkAQ== 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 45B561391B; Thu, 9 Mar 2023 16:02:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QHc4EBYDCmQHbgAAMHmgww (envelope-from <tzimmermann@suse.de>); Thu, 09 Mar 2023 16:02:30 +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 065/101] fbdev/pxafb: Parse option string with struct option_iter Date: Thu, 9 Mar 2023 17:01:25 +0100 Message-Id: <20230309160201.5163-66-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?1759907608841028093?= X-GMAIL-MSGID: =?utf-8?q?1759907608841028093?= |
Series |
fbdev: Fix memory leak in option parsing
|
|
Commit Message
Thomas Zimmermann
March 9, 2023, 4:01 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/pxafb.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c index c46ed78298ae..d2db9c20d515 100644 --- a/drivers/video/fbdev/pxafb.c +++ b/drivers/video/fbdev/pxafb.c @@ -32,6 +32,7 @@ * All Rights Reserved */ +#include <linux/cmdline.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> @@ -2011,23 +2012,26 @@ static int parse_opt(struct device *dev, char *this_opt, return 0; } -static int pxafb_parse_options(struct device *dev, char *options, +static int pxafb_parse_options(struct device *dev, const char *options, struct pxafb_mach_info *inf) { + struct option_iter iter; char *this_opt; int ret; - if (!options || !*options) - return 0; - dev_dbg(dev, "options are \"%s\"\n", options ? options : "null"); - /* could be made table driven or similar?... */ - while ((this_opt = strsep(&options, ",")) != NULL) { + option_iter_init(&iter, options); + + while (option_iter_next(&iter, &this_opt)) { + /* could be made table driven or similar?... */ ret = parse_opt(dev, this_opt, inf); if (ret) return ret; } + + option_iter_release(&iter); + return 0; }