From patchwork Sat Oct 28 10:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 159258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1146946vqb; Sat, 28 Oct 2023 03:42:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5vsJgq2cF+NmXuHPl/asQBI6Qxg066H4KgGU/1cO66VLo82m6ZM6puC/E5TO8obmVVx3p X-Received: by 2002:a92:c242:0:b0:34f:7e36:5f8b with SMTP id k2-20020a92c242000000b0034f7e365f8bmr8178986ilo.25.1698489754740; Sat, 28 Oct 2023 03:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698489754; cv=none; d=google.com; s=arc-20160816; b=FAprxmEr6tVNBt8VMOadG+6F3DQqERQMo7RecPfHD99rF8QElic/wFAQ9COztutoL0 dTEkNyy76Dua0e4F7lCOTT4Z9d0RG4ld1hvRpIMA2w9jZtx2X7fHJR2kCyNtm1X9P7dy c+RvxO6VbQNMbj7FcElBAxmgCpcc+VXUz6ALhGyTSpw8bYuZ76kXNnru+s0Ib8L3pc7M q+dn9F1AeOul3HRhlUiJ+teRoQFujD/NpfQUXa9mqLBpFKd8SzKAB5SyKxaJZlrAwFIi nlUTwTHGsxjYGklqbye38pcCoPswwTqG8fbxYMO93Q0SGeMKV05AFWmxs0TlDmkDUrcG FqWg== 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=Hvnsw6tiEqX0nnVX9A8IeBCG+0I6cphWZAOIfJoabhA=; fh=hptKUT6gjqDHLx+zod4U+VrOcVTu6nM+tBRQ/73vVTE=; b=OSHk/jUTQOu7zeVSxKsAalhSxwzyEQFUX3oGOfS6cnuDO/N4kVYw8igQAJcs5VXIA4 qEYDVc+QRX8mFhsSR1i1nrEJ2Zd2ZGj7troT1Kt4qdWOp/jBRYJ7TAjmLtLhUpWNf/E/ mDu7V+yeipIvCCOzQPonOj+KLLdg/C8A9By/0fqp4Z2bh/HOnd7JONkS8HZa8kQHWBRJ oQ4UDHNGRMExJ6IfIeu6j0Czq9InchCNA3DziCq/Ix3Mboof5cqB4xXvDOagjthS/Fcu K4+ghe5mbNiwpESEzXitxSynt4a7fO/M+cSasHhhmtDEQMudqqF30IF/X7bzZkJLOZ3w vRKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=d0lOpQhB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id v184-20020a6389c1000000b00565e509dc75si2275853pgd.359.2023.10.28.03.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 03:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=d0lOpQhB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 B6E2080793ED; Sat, 28 Oct 2023 03:41:33 -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 S229700AbjJ1KlY (ORCPT + 28 others); Sat, 28 Oct 2023 06:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjJ1KlX (ORCPT ); Sat, 28 Oct 2023 06:41:23 -0400 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 921BBF2 for ; Sat, 28 Oct 2023 03:41:20 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id wgkmq33su5fs2wgkmqHoZ5; Sat, 28 Oct 2023 12:41:17 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698489678; bh=Hvnsw6tiEqX0nnVX9A8IeBCG+0I6cphWZAOIfJoabhA=; h=From:To:Cc:Subject:Date; b=d0lOpQhBtwL2y5sCjIptt+P+dH2W6OPXgmaBfxhjpgB8MqUnVnn/KWR9ueM0kfAma ZYdNUuU4iApkxoAgDvQE9DDP3T+MITcL0K8W8GOdSGU8Iz2ibQEpc4ukqqRddj2CPU 6CvrakjWoA44h+vaYBzI1Scyzvb0Qos5Iq721fJ5hQ7Q6u8gne0uHcVVrxydHKXk1k DIpjeCF08FrIokT4r1lY8t+NEDWJG1looGecBU/Mel8oQR2uR8xSlcros1L5IWt3Di 63J7VtM6hp1q3Sc/JCqZXowF2JZsOgggNGL0hYHNfVL3eBc+R7LkGnFVvnn38awb2D BxAkdtkcl1Tug== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 28 Oct 2023 12:41:18 +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] usb: dwc2: Use seq_buf instead of hand writing it Date: Sat, 28 Oct 2023 12:41:02 +0200 Message-Id: <4c8b71efe4fe05ed0cc37f33ef774746d4d55299.1698489641.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_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 28 Oct 2023 03:41:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780995593166237062 X-GMAIL-MSGID: 1780995593166237062 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. --- 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..66fb74a70bdd 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 buf; 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(&buf, "%s %d: ", period_name, + period); else - cat_printf(&buf, &buf_size, ", "); + seq_buf_printf(&buf, ", "); printed = true; - cat_printf(&buf, &buf_size, "%d %s -%3d %s", start, - units, start + count - 1, units); + seq_buf_printf(&buf, "%d %s -%3d %s", start, units, + start + count - 1, units); count = 0; } + seq_buf_terminate(&s); + if (printed) print_fn(tmp, print_data); }