From patchwork Thu Mar 9 16:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 67014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp389666wrd; Thu, 9 Mar 2023 08:35:27 -0800 (PST) X-Google-Smtp-Source: AK7set+VOLnHx2gTdeJ0oReKouRlaEaQyIJZJZjOKmv4MY5PGyZB5TLFK5g4xNL9DLDmiOEwLOaj X-Received: by 2002:a17:90b:4c49:b0:237:99b9:c415 with SMTP id np9-20020a17090b4c4900b0023799b9c415mr23883249pjb.38.1678379727309; Thu, 09 Mar 2023 08:35:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678379727; cv=none; d=google.com; s=arc-20160816; b=s44wQND7BA1h8VMxbzLsiOABBdqXKwxQ6Ru8r0LeaY0Bei0XeVpENlNIWm4ffvEmiH eM6kVQ5VGJ518LjocxCHlbbZQOKLSHtsdFP6sd6HxUsw6x2wkE1KxnDh7yX1uw25GC3Z abt/KNT90JGR1S6jbcHaY0XhNMmicYiDV3W7+IrxQruo6uLig7RkxbmblwM2b9UHtZQZ qWibN76SJEc7ggE8vQZ/tiEKnTFVpLTOy338hwly0eobnxE0Wl8YXij27pGBx0z8oVJf aBQcn42jRluXCOUlkz0WyqZ3CGz8XsSW6va2nNu78cU+9vdJ4hRCRFnuVUBES4LRcrnF ZWTg== 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=zBQBNruRFSNZlolPcBWrGJ3VsKzDOc5MQ8RhK9SMylU=; b=ebPLaGAvGB9w25RSPFr5E+/RtjLz83qsExEf7Gu4M+zMLwWyVXIRTfxJlaYW8fUxhi aBO8PJFJevoB8TT8zgq+AYNKwnOn2jOIxYz91AYxNTEJ3AQHPh2tx5/Dw8h6jcZr1mhZ Q4kMZVEVTiN8sKlS0pAb1kmwuJF6Ji9IMdPE12HDwaoryPNTY7P8S54j9Z2m4uUX/6Cu UIABLpKm9lCnuA1ooCq5fbu81L+Hor3NToddqS4zGlifA8YKvF4f0H8cv34L6hGplSN1 hdeUjUuEMhrm4fMrZuwS7dhTOxHIelHy6jfUln4rVcYoDtq+2Q2kEnBW1tjlB56HkcmD gFTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TGhSUeAz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=J9Rm0NBD; 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 ca2-20020a17090af30200b00233773a522fsi200231pjb.141.2023.03.09.08.35.12; Thu, 09 Mar 2023 08:35:27 -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=TGhSUeAz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=J9Rm0NBD; 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 S231389AbjCIQI4 (ORCPT + 99 others); Thu, 9 Mar 2023 11:08:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbjCIQCd (ORCPT ); Thu, 9 Mar 2023 11:02:33 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED377F7ED7; Thu, 9 Mar 2023 08:02:32 -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 69DA320190; Thu, 9 Mar 2023 16:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678377751; 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=zBQBNruRFSNZlolPcBWrGJ3VsKzDOc5MQ8RhK9SMylU=; b=TGhSUeAz++JXt77WCiLYR+LnHm9NTwtouH57PfcrnypMafHbIMYvZ3j1t3pgOskxp8BZC4 GrDAqDsOARGADkhF9XQ7ByB8mFanj71S2MGXf32LTNjalW/QS/2DCK+FvDCST9oRi2UKEY hUhz0jrJznh+WJS2lVI5qa98IbI//kM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678377751; 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=zBQBNruRFSNZlolPcBWrGJ3VsKzDOc5MQ8RhK9SMylU=; b=J9Rm0NBDh4ETa4lT0gih7jpI9Z4JH5I7yt4ZY1k5h8IQaaCdRuAqbDD1odTkr9TuW8me5n 0M8rrLC4hFVAL0CQ== 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 13DB31391B; Thu, 9 Mar 2023 16:02:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oN4EBBcDCmQHbgAAMHmgww (envelope-from ); Thu, 09 Mar 2023 16:02:31 +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 067/101] fbdev/rivafb: Parse option string with struct option_iter Date: Thu, 9 Mar 2023 17:01:27 +0100 Message-Id: <20230309160201.5163-68-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?1759908700522148262?= X-GMAIL-MSGID: =?utf-8?q?1759908700522148262?= 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 --- drivers/video/fbdev/riva/fbdev.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c index 8a7dc7452938..7f35edad249e 100644 --- a/drivers/video/fbdev/riva/fbdev.c +++ b/drivers/video/fbdev/riva/fbdev.c @@ -30,6 +30,7 @@ */ #include +#include #include #include #include @@ -2106,17 +2107,18 @@ static void rivafb_remove(struct pci_dev *pd) * ------------------------------------------------------------------------- */ #ifndef MODULE -static int rivafb_setup(char *options) +static int rivafb_setup(const char *options) { + struct option_iter iter; char *this_opt; NVTRACE_ENTER(); - if (!options || !*options) - return 0; - while ((this_opt = strsep(&options, ",")) != NULL) { + option_iter_init(&iter, options); + + while (option_iter_next(&iter, &this_opt)) { if (!strncmp(this_opt, "forceCRTC", 9)) { - char *p; + const char *p; p = this_opt + 9; if (!*p || !*(++p)) continue; @@ -2139,6 +2141,9 @@ static int rivafb_setup(char *options) mode_option = mode_option_buf; } } + + option_iter_release(&iter); + NVTRACE_LEAVE(); return 0; }