From patchwork Thu Mar 9 16:02:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 67026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp390085wrd; Thu, 9 Mar 2023 08:36:16 -0800 (PST) X-Google-Smtp-Source: AK7set9sLSECEgWy+xpxnY5vfrrcn8lQN7X3XRom2lOO5qgTWSl4eGFWYNiaC+4WyyBNj9doaYNi X-Received: by 2002:a17:903:48d:b0:19c:ff0a:2c7e with SMTP id jj13-20020a170903048d00b0019cff0a2c7emr18673113plb.33.1678379775706; Thu, 09 Mar 2023 08:36:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678379775; cv=none; d=google.com; s=arc-20160816; b=wfQP2HsYguKHBB3g+PsyXINcJjsTjh94RGG7gD1nKuhsHtAvovz21B6vyXx/Oz0xM/ Dfcc76w7WynD4KCvwashNm7/g59fl9Bp/nl/T+GLrwBc1Li5lntaxZGDgjTgQPrXKav9 G4hMPFVk3tOwlAoGMxnmjwh5evyS9bz+e4TRU3pdgVdOKqIekxlVKrTqg1tvuwug9LOT /nWLs9mfr/Fb9+sVs5h0uaFMUZH6NUH5S8s/lYPnJKUVp3Has0k/byxxngWWJo95qABl lyCSL58r9BzJRFNyozzxMMRbDC5nAQpELOVPtvAwHDjsuib0bALi+kfo+1aBOskUWuao 4tXg== 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=ALsO4IX+lXOr2/9jJ7xM7oWEJtpk0lY0JvNUM21acD0=; b=hfyLKWUatwHLtaFnP8CnHn9HlMIJzXRvSWeMwme8DK3tl6tbmJ5ibsscGv1Y4zIbLu SUYkAjONEAOQRHyZNzQYdnavHV6b+mLXZn/C4fQgSclhu8qxda/P1rQFeP2KCKqjKzmG UY9SJTYDFyN6Yuka55wsWU6CrbTWUrEwoX/Yo5mem3leh1N2OHtX5jv7kXYF470dTO81 Bo3aXNaFpAFdG1wQ440JPJWglXbNuxCxezKnHBR+2Rjc9u0iHP/3rzXU4wZwn8c/8bOG x7UCyTeQKiP8RaXPd7hDYnFQ7u8iKb5exUWeq//Bqyg68rnYnTwO9N0imqWbpPrR7Men RWYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ibeXiYlR; dkim=neutral (no key) header.i=@suse.de header.b=LWt569Ff; 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 z14-20020a1709027e8e00b0019316d9e4c8si17136690pla.373.2023.03.09.08.36.00; Thu, 09 Mar 2023 08:36:15 -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=ibeXiYlR; dkim=neutral (no key) header.i=@suse.de header.b=LWt569Ff; 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 S232896AbjCIQLS (ORCPT + 99 others); Thu, 9 Mar 2023 11:11:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbjCIQDR (ORCPT ); Thu, 9 Mar 2023 11:03:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA282F7EDF; Thu, 9 Mar 2023 08:02:46 -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 3014E21CF8; Thu, 9 Mar 2023 16:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678377765; 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=ALsO4IX+lXOr2/9jJ7xM7oWEJtpk0lY0JvNUM21acD0=; b=ibeXiYlRwFX3kYpd0p9A7lMTdVMC9Fwe5CosSJaVaakK7R2YBZ3fXTlozkbl/UiL5jTS8y xXFPFpQgBHAUE6pmwaV+xKG4iGnskk7Y/bPBzSTtL3W77qowzQ6ugXnIq17I+ZiAI5CtbK U2JPW0KhaLVuLn52/QgPlViOuwijmU4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678377765; 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=ALsO4IX+lXOr2/9jJ7xM7oWEJtpk0lY0JvNUM21acD0=; b=LWt569FfZOyzTosHPQg/ga7WhTjnw20OX+GhU9e53/rp4wj+b9RmbVDPnRjtEZlMaiCGP9 F9Wa7b7tLTzP6RAg== 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 C26901391B; Thu, 9 Mar 2023 16:02:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EDJ2LiQDCmQHbgAAMHmgww (envelope-from ); Thu, 09 Mar 2023 16:02:44 +0000 From: Thomas Zimmermann 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 Subject: [PATCH v2 100/101] staging/sm750fb: Parse option string with struct option_iter Date: Thu, 9 Mar 2023 17:02:00 +0100 Message-Id: <20230309160201.5163-101-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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759908751784312964?= X-GMAIL-MSGID: =?utf-8?q?1759908751784312964?= 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: * move string handling into separate patches Signed-off-by: Thomas Zimmermann --- drivers/staging/sm750fb/sm750.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index f0dbf7535ca8..0e3712fcf0e0 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -867,8 +868,9 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index) } /* chip specific g_option configuration routine */ -static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src) +static void sm750fb_setup(struct sm750_dev *sm750_dev, const char *src) { + struct option_iter iter; char *opt; int swap; @@ -889,7 +891,9 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src) goto NO_PARAM; } - while ((opt = strsep(&src, ":")) != NULL && *opt != 0) { + option_iter_init(&iter, src); + + while (option_iter_next(&iter, &opt)) { dev_info(&sm750_dev->pdev->dev, "opt=%s\n", opt); dev_info(&sm750_dev->pdev->dev, "src=%s\n", src); @@ -924,6 +928,8 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src) } } + option_iter_release(&iter); + NO_PARAM: if (sm750_dev->revid != SM750LE_REVISION_ID) { if (sm750_dev->fb_count > 1) { @@ -1095,9 +1101,10 @@ static void lynxfb_pci_remove(struct pci_dev *pdev) iounmap(sm750_dev->pvMem); } -static int __init lynxfb_setup(char *options) +static int __init lynxfb_setup(const char *options) { size_t len; + struct option_iter iter; char *opt, *outbuf; if (!options || !*options) { @@ -1113,16 +1120,9 @@ static int __init lynxfb_setup(char *options) return -ENOMEM; g_settings = outbuf; - /* - * Notes: - * char * strsep(char **s,const char * ct); - * @s: the string to be searched - * @ct :the characters to search for - * - * strsep() updates @options to pointer after the first found token - * it also returns the pointer ahead the token. - */ - while ((opt = strsep(&options, ":")) != NULL) { + option_iter_init(&iter, options); + + while (option_iter_next(&iter, &opt)) { /* options that mean for any lynx chips are configured here */ if (!strncmp(opt, "noaccel", strlen("noaccel"))) { g_noaccel = 1; @@ -1139,6 +1139,8 @@ static int __init lynxfb_setup(char *options) } } + option_iter_release(&iter); + /* misc g_settings are transport to chip specific routines */ pr_info("parameter left for chip specific analysis:%s\n", g_settings); return 0;