From patchwork Sat Oct 28 16:05:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 159279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1291429vqb; Sat, 28 Oct 2023 09:05:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgXJOMY6V+83i1YUY18vZwECRYVKdqdevBKqgQEm4pz+6d33M7Y5e0TJCsnKGjMSSrw39E X-Received: by 2002:a05:6a00:24c4:b0:68f:c078:b0c9 with SMTP id d4-20020a056a0024c400b0068fc078b0c9mr7289161pfv.11.1698509115167; Sat, 28 Oct 2023 09:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698509115; cv=none; d=google.com; s=arc-20160816; b=ZFmoemFejiK5Ghuy4RsqGSgJZN9ywRGEzeFrImk7dSsPyeGQSDzMjfpRPJQMQ4xr6k W/ynM5B8PlXdTokon4ShY42v3uK92bR08TKZgeyl7GZNfZtHiv3uHswmUtT+Ey6Afv1m fh8l3s7Le00IcHJOY0QaMzSXrzN+ad9e/ok0LEew0qDfevQoL7OUQ9X+UO27tvRkwNt7 WSXnfGneyXOAZfOgL8OTEapL34EnP4TSar5u5EKSNqmYlo8yXpUzGkShc0fUu6nnkdk7 NKUHhUgLOzJU170Ce0iZmL5u0bUS3c1kl6kozewHLzyZwS0ha6nVpN8AVI9rwXkZOg4Y B72g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=lJV0nrXGftDw+3aoT/GoqGQ9MO17enJwu7GrGnJ+O5s=; fh=hptKUT6gjqDHLx+zod4U+VrOcVTu6nM+tBRQ/73vVTE=; b=cr/kr3KohJSYu19D6pBCVi7E2NHQKDtu8aEJqF958DIEmcJCI2KsSKSfiJikhGAVkN XOByMx5pDq7x7rkQHKO+2tshvXckzvNoOXe3tT3VdOAc6r+6oS6Hi4EQ0xxstNia7R3r R5oy8eSj21/0rZe/8HHGzgKr5r626jSez1yl+S+Gvony7jEoMLTYxPgo2O0A4GxaL6DA UuO8+cjo9eMCisUyzJ6BoLCcmz47mpvLUxl9/Q2MUOHVsy4h2a6rQraxk1Qkk4dKEg7w XPx8Bxoxpdj+Mgy4MjxA5xvHxLIN1HjTmHW9XNclf64tXuHaIQfKZ/9cqD3BResNHeMN K4ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=m2c4u+Ew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c24-20020aa78c18000000b006bf2e5f0840si2580514pfd.67.2023.10.28.09.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 09:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=m2c4u+Ew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 33A5380A73E2; Sat, 28 Oct 2023 09:05:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229459AbjJ1QFJ (ORCPT + 28 others); Sat, 28 Oct 2023 12:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjJ1QFI (ORCPT ); Sat, 28 Oct 2023 12:05:08 -0400 Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EE74ED for ; Sat, 28 Oct 2023 09:05:04 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id wlo5q1cN8yBwnwlo6qKaMv; Sat, 28 Oct 2023 18:05:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698509103; bh=lJV0nrXGftDw+3aoT/GoqGQ9MO17enJwu7GrGnJ+O5s=; h=From:To:Cc:Subject:Date; b=m2c4u+Ew1ymLvM7aeveClQml6joGS6GtBS/tZTl21IhQB0cobcEtGP1V2iVVyi3Gn 8gnVIMtkaBD96x9AJvnMpQA0Sb5LTYM/xzYCpQWQ4fcIrRO99EARgVybpzQOKWRyg8 qVB6OYn9fNjCIbKMUj+06GIB/8Flz7EueT+1TEFob++hnkxZM0WKUoXHn0gZAVcauP cJc3ie0Vs6AbpXi/nFyUIofgBQtlsGWKTRnI4Gv67UVWUWojLBQJeFh1B+Cq69vNYt tM9WHgAvwBVlEp3OJzNKzWQlZUJNggzNnqU/wVeoFjvOrcUDhnPdG9A7O8p+9A/hDo 7qxkmxbxWNtMQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 28 Oct 2023 18:05:03 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Minas Harutyunyan , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-usb@vger.kernel.org Subject: [PATCH v2] usb: dwc2: Use seq_buf instead of hand writing it Date: Sat, 28 Oct 2023 18:05:00 +0200 Message-Id: <4eafde20b0fb4894a00f9749a2b17e847a7efa8c.1698509078.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 28 Oct 2023 09:05:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780995593166237062 X-GMAIL-MSGID: 1781015893847442336 cat_printf() re-implements what the seq_buf API does. So, switch to the seq_buf API to save some line of code. Signed-off-by: Christophe JAILLET --- seq_buf_printf(&buf, ", "); could be seq_buf_puts(), but the result could be slightly different. So I kept a conservative approach. If only some seq_buf_printf() are used, the final seq_buf_terminate() can be avoided, but I think it is cleaner with it. Changes in v2: - compile tested with DWC2_PRINT_SCHEDULE defined - Fix some built issues v1: https://lore.kernel.org/all/4c8b71efe4fe05ed0cc37f33ef774746d4d55299.1698489641.git.christophe.jaillet@wanadoo.fr/ --- drivers/usb/dwc2/hcd_queue.c | 53 ++++++++---------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c index 0d4495c6b9f7..4edb87c4247c 100644 --- a/drivers/usb/dwc2/hcd_queue.c +++ b/drivers/usb/dwc2/hcd_queue.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -359,41 +360,6 @@ static unsigned long *dwc2_get_ls_map(struct dwc2_hsotg *hsotg, } #ifdef DWC2_PRINT_SCHEDULE -/* - * cat_printf() - A printf() + strcat() helper - * - * This is useful for concatenating a bunch of strings where each string is - * constructed using printf. - * - * @buf: The destination buffer; will be updated to point after the printed - * data. - * @size: The number of bytes in the buffer (includes space for '\0'). - * @fmt: The format for printf. - * @...: The args for printf. - */ -static __printf(3, 4) -void cat_printf(char **buf, size_t *size, const char *fmt, ...) -{ - va_list args; - int i; - - if (*size == 0) - return; - - va_start(args, fmt); - i = vsnprintf(*buf, *size, fmt, args); - va_end(args); - - if (i >= *size) { - (*buf)[*size - 1] = '\0'; - *buf += *size; - *size = 0; - } else { - *buf += i; - *size -= i; - } -} - /* * pmap_print() - Print the given periodic map * @@ -417,8 +383,7 @@ static void pmap_print(unsigned long *map, int bits_per_period, for (period = 0; period < periods_in_map; period++) { char tmp[64]; - char *buf = tmp; - size_t buf_size = sizeof(tmp); + struct seq_buf s; int period_start = period * bits_per_period; int period_end = period_start + bits_per_period; int start = 0; @@ -426,6 +391,8 @@ static void pmap_print(unsigned long *map, int bits_per_period, bool printed = false; int i; + seq_buf_init(&s, tmp, sizeof(tmp)); + for (i = period_start; i < period_end + 1; i++) { /* Handle case when ith bit is set */ if (i < period_end && @@ -442,17 +409,19 @@ static void pmap_print(unsigned long *map, int bits_per_period, continue; if (!printed) - cat_printf(&buf, &buf_size, "%s %d: ", - period_name, period); + seq_buf_printf(&s, "%s %d: ", period_name, + period); else - cat_printf(&buf, &buf_size, ", "); + seq_buf_printf(&s, ", "); printed = true; - cat_printf(&buf, &buf_size, "%d %s -%3d %s", start, - units, start + count - 1, units); + seq_buf_printf(&s, "%d %s -%3d %s", start, units, + start + count - 1, units); count = 0; } + seq_buf_terminate(&s); + if (printed) print_fn(tmp, print_data); }