Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3986040imm; Wed, 5 Sep 2018 08:57:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbaeMCNV53rZdufqJVPsjk0OGdQAyDOAYFewKaVqBLBTIBnbyQayBbMawEDxX8x6IyVY/p8 X-Received: by 2002:a17:902:7c8c:: with SMTP id y12-v6mr36795380pll.283.1536163072165; Wed, 05 Sep 2018 08:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536163072; cv=none; d=google.com; s=arc-20160816; b=yBLcPC0mhPJb8E79SZsNbEHQIJzTleaosqz3eS4ySAV5fen3YLf9Add61JnbB7Nhd+ hIpwS2TAaYBO+3ajk6vGyRnBtHFVSd5te3R8qcqBTYgFYWMtG1wkEGIh0Ik0PB6Vr2d8 GFG7nTTL5oJfijEX+N36k17jHL4bFgI0HoWVvE00uqCsKUs4xOOJsoR4DHuHeI77T9yM FsjJRBFH0GIl+xBAWoZF5mCIoBhWVImL31fr5frrjusx7ZivWgXwkF70EuQ6BMI6xVTI eKMHTKrWKZjMI6W/Xk+yTmnBvQtv+lvZGDLIRbm/N5DM1qx/5ymCQSQzffAI6yNF8rwM /Hnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=lFnB4+jvqKKiUjFz3Ws9i40kOYgq8OCH5S5FTn2i6iU=; b=OhwcXxSCgrED7LLSYh1jB1eTa1YMEtwJzbKgccNO+RoavAE2Fh1iL0N7Qv2Yf1G2PX UUhB34QqhGIv5v+MqLckhz58BCA2HjunZyR/aQ05WimDDLVaWY8Z3xSdK/IM7P830ViN PUco5UcMJfs280/3vx2ryJrHA5WTJagkV8c+KLMFKi0hhF/1wBaI+jSuo+9g5I/aHk/e KjQwjKbUavenP0r+pa4kdbb5wU1apd1XUFDTviT3XUXA1ArAjqqc73yeAXGBtgl2Dpeb BKRujncOFSDNdyVhW0suMSIBJ21rSxTANl4NjBpfRzmN6D4ZLJ780CJlDUfAB1OoZ6Iu 4P1g== ARC-Authentication-Results: i=1; mx.google.com; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24-v6si2317842pgi.515.2018.09.05.08.57.37; Wed, 05 Sep 2018 08:57:52 -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; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbeIEU01 (ORCPT + 99 others); Wed, 5 Sep 2018 16:26:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50592 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726189AbeIEU01 (ORCPT ); Wed, 5 Sep 2018 16:26:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09A9D4026128; Wed, 5 Sep 2018 15:55:39 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-84.rdu2.redhat.com [10.10.123.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2082F2156701; Wed, 5 Sep 2018 15:55:38 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers From: David Howells To: linux-api@vger.kernel.org, linux-kbuild@vger.kernel.org Cc: Dan Williams , linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, dhowells@redhat.com Date: Wed, 05 Sep 2018 16:55:37 +0100 Message-ID: <153616293757.23468.13765050528392604035.stgit@warthog.procyon.org.uk> In-Reply-To: <153616286704.23468.584491117180383924.stgit@warthog.procyon.org.uk> References: <153616286704.23468.584491117180383924.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 05 Sep 2018 15:55:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 05 Sep 2018 15:55:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fix this by defining a label in the enum that indicates the number of commands. (2) g++ does not support "non-trivial" array initialisers fully yet. Fix this by defining the missing intermediate values. (3) Every file that calls this function will acquire a copy of names[]. The same goes for nvdimm_cmd_name(). A better way would be to remove these functions and their arrays from the header entirely. Signed-off-by: David Howells cc: Dan Williams cc: linux-nvdimm@lists.01.org --- include/uapi/linux/ndctl.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/ndctl.h b/include/uapi/linux/ndctl.h index 7e27070b9440..9c89159f6a0f 100644 --- a/include/uapi/linux/ndctl.h +++ b/include/uapi/linux/ndctl.h @@ -117,6 +117,7 @@ enum { ND_CMD_VENDOR_EFFECT_LOG = 8, ND_CMD_VENDOR = 9, ND_CMD_CALL = 10, + nr__ND_CMD = 11 }; enum { @@ -128,22 +129,29 @@ enum { static inline const char *nvdimm_bus_cmd_name(unsigned cmd) { - static const char * const names[] = { + static const char * const names[nr__ND_CMD] = { + [0] = NULL, [ND_CMD_ARS_CAP] = "ars_cap", [ND_CMD_ARS_START] = "ars_start", [ND_CMD_ARS_STATUS] = "ars_status", [ND_CMD_CLEAR_ERROR] = "clear_error", + [5] = NULL, + [6] = NULL, + [7] = NULL, + [8] = NULL, + [9] = NULL, [ND_CMD_CALL] = "cmd_call", }; - if (cmd < ARRAY_SIZE(names) && names[cmd]) + if (cmd < nr__ND_CMD && names[cmd]) return names[cmd]; return "unknown"; } static inline const char *nvdimm_cmd_name(unsigned cmd) { - static const char * const names[] = { + static const char * const names[nr__ND_CMD] = { + [0] = NULL, [ND_CMD_SMART] = "smart", [ND_CMD_SMART_THRESHOLD] = "smart_thresh", [ND_CMD_DIMM_FLAGS] = "flags", @@ -156,7 +164,7 @@ static inline const char *nvdimm_cmd_name(unsigned cmd) [ND_CMD_CALL] = "cmd_call", }; - if (cmd < ARRAY_SIZE(names) && names[cmd]) + if (cmd < nr__ND_CMD && names[cmd]) return names[cmd]; return "unknown"; }