Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4214332imm; Tue, 25 Sep 2018 13:23:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV635ptwOFs2cEGHKtCLzuTwhKFwihfYe04R24yLWFjPuFdzmg8rWBWXN2+wEqS5GSfDzf6JU X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr2710459plb.322.1537906992559; Tue, 25 Sep 2018 13:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537906992; cv=none; d=google.com; s=arc-20160816; b=RHwr7jsfOA7r3GJNSb1FizmuVn5bUQLP5itWP43t5tYJgRbxAllZBb+JD7Yo6yNkq6 Lv4m1suhNG8y1gOo6iqMpznPQNRMx5MxKHnFqbEdMjY0EKnRj1zO2z2nqjO383C+PCgo l1/xqs2HxAwZSTHjcfmMJxBLoBpNfnzoII0h0cc79sGmMg/DZLJU3m/ZCaqaUi3mYbbo 7YzQXVISonZn4LQsPjQcRH20Yyhxo/tCYeCb6quaOCz9IDB3ivcWtDDW2OGG7t9TFJvb hUbigEy0ljeJpwO5fxgjdPK5GhLKwzoj3sl3lwk3mh0uBZH21CXy5Q0H+RZuXruy3iqZ s/mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=U+RsP1YWy/+85yH5m6ZF3EeMOB34juFDKmKvaVyR9M0=; b=w2XtN5OumBqlYEDy6KsBN10fBZiaHleM1RnbSbbIuNkSmp5wtJ7MeIMSivlV7xa2/5 xekJeCY5jl8hjWr68epBL+RcqLu8XsuR3AS6sK+zFANxO6yl2AWzKXXmG0DtjX4n2YTE nm5oOTX58++A5hIiwbyK+Fk0ztWJ2LUfk9IPEjU83VH3G/KBbRhTkz00b3YhN/uVe9Zz VvMG+yBPmljLRD40BM6HkgqPJad4cd7AXhQlI2XYP0V6oB7DY+v6Yn+hFuX4QaGCHDJu tZU16h3l9ZXnYoqjNbSslAyElW6kjEYiwGIotSPA70M3JRTvTdyjXNkjYOB5fbyymsU7 ZOCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=w5eb11kr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18-v6si3085367pfk.65.2018.09.25.13.22.57; Tue, 25 Sep 2018 13:23:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=w5eb11kr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726377AbeIZCbt (ORCPT + 99 others); Tue, 25 Sep 2018 22:31:49 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:37489 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbeIZCbt (ORCPT ); Tue, 25 Sep 2018 22:31:49 -0400 Received: by mail-oi1-f193.google.com with SMTP id n1-v6so2627821oic.4 for ; Tue, 25 Sep 2018 13:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=U+RsP1YWy/+85yH5m6ZF3EeMOB34juFDKmKvaVyR9M0=; b=w5eb11krjyvyLZxXZVsupg/enoWXMkhGPL4+N2qvmyHbmueJxVliQOk2XLkNCz8HhD FtjCVZMpwLBxUSszSY8h09ejUZtA67B2pY9r9WSquA1SqXIDI9lITkNY9SCbba2jTXLO zi5DKO34RzMCxbFl9qumERCH3JjP2dhiPt4QaLeBQ90Iqc8s270w4A2k/qD3wDtlSs0Y 5fJn9yw7htchhD8pa9EfJBf+0OKALjkXofKr2QPTpxehmbB3JmEQ8FNWyZVDSgjO8HBW UH55WV28wuZRYLsa+sTJJlbmWxXKI/Ibw6TV/zJXAL/aPBx+n7oXBQ6A2He1n20G1WsM HrDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=U+RsP1YWy/+85yH5m6ZF3EeMOB34juFDKmKvaVyR9M0=; b=onXo2MS170Q5jQXJ+hgbKprFQ44bzo9OhOtgomngGFOWVdsfcX/mZz+wOPhWBQ09kv RIZu/oYN7fJBE5tziz8QtfmUK5/RSEgdm+1C2cAPISHpN8VrlYo1vqi/WIYgNncCf22j pq+NOOlAoUC/Kid4HAs29Ocj9Xn0Ai7SPBspNnqShYTvwjE89Nf0iLhkJnfCP2lZcJbe zVfvtSwDGjcJK+qJu45YQEgXpjXG3Yx22cxOu8BYSxT/m1JI53EKpeusawFCsDtE4+ML 9YH+ZYkMGUU0C+VtjgYtM8b+MP//Dcke4U257q4TLTwWCbwjG/UYlya9VOuVRoWolDKI vVRA== X-Gm-Message-State: ABuFfoh24lF0lP/cFpskt2ocXKwJWiftT3j5IE1Vx4R0Pz+2F3LpJL+v MaSbwJSGGitqGlXEYgdJLVHQZKc9+KCmya1tvyUgcw== X-Received: by 2002:aca:ce4c:: with SMTP id e73-v6mr1641230oig.225.1537906952298; Tue, 25 Sep 2018 13:22:32 -0700 (PDT) MIME-Version: 1.0 References: <153622549721.14298.8116794954073122489.stgit@warthog.procyon.org.uk> <153622556444.14298.5971956747198405225.stgit@warthog.procyon.org.uk> In-Reply-To: <153622556444.14298.5971956747198405225.stgit@warthog.procyon.org.uk> From: Dan Williams Date: Tue, 25 Sep 2018 13:22:21 -0700 Message-ID: Subject: Re: [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers [ver #2] To: David Howells Cc: Linux API , linux-kbuild@vger.kernel.org, linux-nvdimm , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 6, 2018 at 2:19 AM David Howells wrote: > > The following code in the linux/ndctl header file: > > static inline const char *nvdimm_bus_cmd_name(unsigned cmd) > { > static const char * const names[] = { > [ND_CMD_ARS_CAP] = "ars_cap", > [ND_CMD_ARS_START] = "ars_start", > [ND_CMD_ARS_STATUS] = "ars_status", > [ND_CMD_CLEAR_ERROR] = "clear_error", > [ND_CMD_CALL] = "cmd_call", > }; > > if (cmd < ARRAY_SIZE(names) && names[cmd]) > return names[cmd]; > return "unknown"; > } > > is broken in a number of ways: > > (1) ARRAY_SIZE() is not generally defined. > > (2) g++ does not support "non-trivial" array initialisers fully yet. > > (3) Every file that calls this function will acquire a copy of names[]. > > The same goes for nvdimm_cmd_name(). > > Fix all three by converting to a switch statement where each case returns a > string. That way if cmd is a constant, the compiler can trivially reduce it > and, if not, the compiler can use a shared lookup table if it thinks that is > more efficient. > > A better way would be to remove these functions and their arrays from the > header entirely. > > Signed-off-by: David Howells > cc: Dan Williams Acked-by: Dan Williams ...again let me know if you'll take this with g++ series or want me to carry it directly.