Message ID | 20230306160016.4459-52-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 v21csp1924117wrd; Mon, 6 Mar 2023 08:05:23 -0800 (PST) X-Google-Smtp-Source: AK7set9gT2JMeOWUs3vr9Uuf0QhbiSPJ286zbQCHSFiy5Vc7eGCOfg1g8Kn3jF99qEbHXLAd9F6w X-Received: by 2002:a05:6402:330:b0:4d0:c131:dbc6 with SMTP id q16-20020a056402033000b004d0c131dbc6mr8010411edw.24.1678118723014; Mon, 06 Mar 2023 08:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678118722; cv=none; d=google.com; s=arc-20160816; b=stemT/kevrmkMprK6LTOoyxor02qdNjGsw6GyLqCIzRJwQyE7oZgidmeu8MMrHu6Oi BE+BzUKz+U8HCu7owqlXuHI0MHp0h9V6p5YUs53g0OHSuVhllMppb6w4hwSK3DbnWau1 e5Nc6OpW/1DNEL6QQboTKbtdpo/02miu+wjC8ewPC1oAQ0OfKyUPctHpMqxHqnnFYoPD V+WRNBiZKPXUYIvSxQCIlhOCdkqCI9buHIi35Vy39SUVQs5GTilNJ/2lM2Mp5d4lvItY zAb+UwfdIm4qkBeC1so3zpSVUxemJoFnBUezL/UkUUzWAg3E7KuzSp20qkOWe7HnXf5Q 5GVA== 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=GdlBvpQCtFANkdgtqm8ATrYFTI/ql2Egv02ZUyDqJ8o=; b=roP1MgGSICAXSJ/Yx1eqrtHNTDJi3R9gGMjquqCg4tYDU+ildIskjQhfb6bTo3+i4e 0ImPSQ85lZ2eiI0ka/HctEMrjmCTDLvgmOjLXxc5xKTEIpmCnipxMh9px9yjxh7JfR5S 5M9/rfpwN6SUXvzpZfZi+KYulcm+dY4jUOiVWa1qP2ctL1k/Tetvpt3EH2JX+hLWUm0i ib6zc3jZeMbPVBozEt3YpJ4ZscNh58t96xENI0YdJtWI+zX3X26/UlsRnsG0hR4iOBnf D0N1UQlOpyzEqL95tXtjKr/IjBHN+gyzHPKELVlP48J6dK2Nsei8irXOy44dpTiSb7Py WURQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HCZQ0kRD; dkim=neutral (no key) header.i=@suse.de; 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 i6-20020a056402054600b004ace0fce44asi11338830edx.521.2023.03.06.08.04.59; Mon, 06 Mar 2023 08:05:22 -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=HCZQ0kRD; dkim=neutral (no key) header.i=@suse.de; 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 S229622AbjCFQD6 (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 6 Mar 2023 11:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbjCFQAr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Mar 2023 11:00:47 -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 A91462E813; Mon, 6 Mar 2023 08:00:45 -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 F0CE8223F5; Mon, 6 Mar 2023 16:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678118443; 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=GdlBvpQCtFANkdgtqm8ATrYFTI/ql2Egv02ZUyDqJ8o=; b=HCZQ0kRDvWLtfqeDNYrYdSQ5fA3xEzhdgqLwHl+t6jQxmCQDXXqqHRjZnVdQq7GmTqRPi6 eclrzaKX4l4SdJ2lQRmRd39SCd1aouKWj1l5/LyVC38Ca1AGZ3HQWxQQDgg3QDtZeUuqvC 9dRlhbPiwqT9LvKb+Vnxac5h4MDMNQc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678118443; 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=GdlBvpQCtFANkdgtqm8ATrYFTI/ql2Egv02ZUyDqJ8o=; b=Hd+sMIb0Mlk7afi9BKsvEL4L3ph/cRvshwvmOsYdJEdvckMpsdPLTwcceaEJrWqc+tzWxG rHEKgviagQh1ZLDQ== 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 94A3613513; Mon, 6 Mar 2023 16:00:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gO9JIysOBmQ/PwAAMHmgww (envelope-from <tzimmermann@suse.de>); Mon, 06 Mar 2023 16:00:43 +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 51/99] fbdev/nvidiafb: Parse option string with struct option_iter Date: Mon, 6 Mar 2023 16:59:28 +0100 Message-Id: <20230306160016.4459-52-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?1759635017920117620?= X-GMAIL-MSGID: =?utf-8?q?1759635017920117620?= |
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/nvidia/nvidia.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c index eb91201babd4..58b1b13f09dd 100644 --- a/drivers/video/fbdev/nvidia/nvidia.c +++ b/drivers/video/fbdev/nvidia/nvidia.c @@ -10,6 +10,7 @@ */ #include <linux/aperture.h> +#include <linux/cmdline.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> @@ -1458,17 +1459,18 @@ static void nvidiafb_remove(struct pci_dev *pd) * ------------------------------------------------------------------------- */ #ifndef MODULE -static int nvidiafb_setup(char *options) +static int nvidiafb_setup(const char *options) { - char *this_opt; + struct option_iter iter; + const 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)) @@ -1510,6 +1512,9 @@ static int nvidiafb_setup(char *options) mode_option = mode_option_buf; } } + + option_iter_release(&iter); + NVTRACE_LEAVE(); return 0; }