From patchwork Tue Mar 23 13:03:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406871 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4433115jai; Tue, 23 Mar 2021 06:04:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU6b5QIzKCyv/vObBGkchNoQvJgArN6G8FMttolDMvAfHkwZ3MvzeB/cwl5r+NwGiOMrC/ X-Received: by 2002:a05:6402:278b:: with SMTP id b11mr4504646ede.380.1616504689903; Tue, 23 Mar 2021 06:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504689; cv=none; d=google.com; s=arc-20160816; b=JhuhHUim7sdmcb6TavGmbHBoa+Ty+/8Kjsny+AqHBx3ccEJlLCnmsTOztjdETinIxa g8TVXVtsPZK8ARiki/X7UOqDUk+EQcpuPks3VZTfWKW4nWFV+Py6LJuaClDWHyJOn5gK +gevyDZMsUYXL/UYxIRWYTGrX5Wc0QAjqx2MXaMi12ydNzR33wwiE3TRf7JUBn0h32+8 bpgA9ODGFW8icMKba3glQw48WWadQgej489D4JfvY1TlQwYUQOhbIoUSVrUC+Ojnm7dp NuO8+ocBJ1wqtmfejg3vuUS5NPhzVxe1i5Io0gACYlqcW0APipuZAgiEYC1OyBLCJVBM hQJg== 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=W9lEUOHjPAkfBIiDJm1MJr7qFGtS7o8wj9met79rEZM=; b=eecATU8Ns/WZ+KoWv6YV4bJsxKgdnynkl8ngwuUKEoJt0wU2bZLfYk/Gw3dnhGz5x0 CrjeIlchsC9AFgLQnSoIuE09XBDbQCreYDWfOAY6cTMU/KsyLtc0m5A4dYUHhdYo1TmU 6n3D3diksRA2GIWGpbSZg2cpfYVC6YnfMAB8ZmvbdO22LP8uXwucmD1CJnoX+ABTjm2w r5JGaqUQYb7XgVuQa65FNgu0WILmW44Ot0G2Ds0dNhaLfQwZaCmYm8srVshWN4k2PCsh MjR4B5H7z2PjZ50UXu8IAK5450X3TTncArstpfZEMyIAwK823sRK9zwgrSXEd3+gxsRM iuNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cdzpNOFi; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw5si14016238ejc.103.2021.03.23.06.04.46; Tue, 23 Mar 2021 06:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cdzpNOFi; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbhCWNER (ORCPT + 8 others); Tue, 23 Mar 2021 09:04:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbhCWNDn (ORCPT ); Tue, 23 Mar 2021 09:03:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FB2C6192D; Tue, 23 Mar 2021 13:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504623; bh=zJzf06RB17EMVuvWgntxsZAzxqtJqr53ucVYYUuK8EU=; h=From:To:Cc:Subject:Date:From; b=cdzpNOFiRFj1xqywlgrtaCm1x2O3E9/6J1vYZ+i3Xn9uIZpSjvmY7wU0ZniYgINSS IOQIsmi4ezhBN9t+2EB4bJoz6PXZriiQ7/XE15WVoBqQSZks0Kn43n1aYZ81QJNeO0 OdUyMQwDyeNTlBzOBydQdboMkFsZzLi1K7tvXC1EwevheelgHtTFgO2WlbpE4t7Qpw inVYe1+v8izZC7jVhJB0wUwi79Fv6KOkmEz7lliOyeRHGk0FcwIz4W06dczEaksbAJ ID8dY92zjNGV9h7Xl36klqqwRFcTDucMBIBmKMnKrQ6a4lTdqEyKHGBm4o3Y2zWJeW jZGEl5QOMsEyQ== From: Arnd Bergmann To: Thomas Graf , Herbert Xu Cc: Arnd Bergmann , Colin Ian King , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rhashtable: avoid -Wrestrict warning on overlapping sprintf output Date: Tue, 23 Mar 2021 14:03:32 +0100 Message-Id: <20210323130338.2213241-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann sprintf() is declared with a restrict keyword to not allow input and output to point to the same buffer: lib/test_rhashtable.c: In function 'print_ht': lib/test_rhashtable.c:504:4: error: 'sprintf' argument 3 overlaps destination object 'buff' [-Werror=restrict] 504 | sprintf(buff, "%s\nbucket[%d] -> ", buff, i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/test_rhashtable.c:489:7: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 489 | char buff[512] = ""; | ^~~~ Rework this function to remember the last offset instead to avoid the warning. Signed-off-by: Arnd Bergmann --- lib/test_rhashtable.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.29.2 diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c index 76c607ee6db5..5a1dd4736b56 100644 --- a/lib/test_rhashtable.c +++ b/lib/test_rhashtable.c @@ -487,6 +487,7 @@ static unsigned int __init print_ht(struct rhltable *rhlt) struct rhashtable *ht; const struct bucket_table *tbl; char buff[512] = ""; + int offset = 0; unsigned int i, cnt = 0; ht = &rhlt->ht; @@ -501,18 +502,18 @@ static unsigned int __init print_ht(struct rhltable *rhlt) next = !rht_is_a_nulls(pos) ? rht_dereference(pos->next, ht) : NULL; if (!rht_is_a_nulls(pos)) { - sprintf(buff, "%s\nbucket[%d] -> ", buff, i); + offset += sprintf(buff + offset, "\nbucket[%d] -> ", i); } while (!rht_is_a_nulls(pos)) { struct rhlist_head *list = container_of(pos, struct rhlist_head, rhead); - sprintf(buff, "%s[[", buff); + offset += sprintf(buff + offset, "[["); do { pos = &list->rhead; list = rht_dereference(list->next, ht); p = rht_obj(ht, pos); - sprintf(buff, "%s val %d (tid=%d)%s", buff, p->value.id, p->value.tid, + offset += sprintf(buff + offset, " val %d (tid=%d)%s", p->value.id, p->value.tid, list? ", " : " "); cnt++; } while (list); @@ -521,7 +522,7 @@ static unsigned int __init print_ht(struct rhltable *rhlt) next = !rht_is_a_nulls(pos) ? rht_dereference(pos->next, ht) : NULL; - sprintf(buff, "%s]]%s", buff, !rht_is_a_nulls(pos) ? " -> " : ""); + offset += sprintf(buff + offset, "]]%s", !rht_is_a_nulls(pos) ? " -> " : ""); } } printk(KERN_ERR "\n---- ht: ----%s\n-------------\n", buff);