Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3481475imu; Sun, 11 Nov 2018 16:05:30 -0800 (PST) X-Google-Smtp-Source: AJdET5cOx1sKP4fHFRtSOH8wypYU/Ht+NStYqI+WXpkv5LdETVzj/62txdzu7+TkjdlTGhgFwgVO X-Received: by 2002:a17:902:9897:: with SMTP id s23-v6mr18288924plp.229.1541981130077; Sun, 11 Nov 2018 16:05:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981130; cv=none; d=google.com; s=arc-20160816; b=nuxc2cLuy5COpZKwmWjOl9VkCKU4NraCM8Ii4/8hLDVHd2IXR0ygr8nGVA4czTKHWo T6fv1VS3XPRItvvF/IlIqoR4Qge17AeI/Y7imH9ZC66pDQehAWL0iRFX2+SOKBE/REp4 Furhnws8eKtrHBDMHp09VBlaWUAD1Lj1Lz1XdC/llDxpKsErHqVzSeJ2E38LELddFQja tG3uZ1B+Z00QQsyLIHhWCy7CTv3Ox9WMcDbt9Ou1lqnK36bACLKCXkSXLqH8Q8PyvD5J 8sHD6k1S1rcN57rjTuXCfoNaOxgf7bxzP2ehZdevWyDxHap0i74hnncp2ueM/nV1UYQ1 9o5A== 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:subject:cc:to :from:dkim-signature; bh=g0mMOvuZLrMUF9q+ja2sw41kdqKZqP5DwPXIj/1HNJA=; b=d+MH2g8EV0hnON6b5U21gJCvXcKnT/U+GlFeszPw3EgKQmVpThR/u/u0PdXZ/CHR5e KTqA4HTBnyToxxK+vuz3+sbTmoTvYtkGYo6eSgHPkaZIaDhlE4I6lvpiqlW/O6WNkbdQ 6Dvp1pqn+LXYUVZWdn4NapAfYfw6RvHJSM4jInmEeWRJx9fzFhf12ng/hGvroZip1VkU 81Lp65PKJ53IcQzneb3UXBP9bvTo8OtYX93LYfmTjvXkcAo5eMOvEW8TeApCb6f5vTjq yxvVEGivsgNLWGePw0IYigQYNy1i6ilZ7ZiQlCZ5U3CrLCchj7NQD2ee5LQ3GlOI9kSf qCEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HUMu9TgX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a34-v6si17049822pld.249.2018.11.11.16.05.15; Sun, 11 Nov 2018 16:05:30 -0800 (PST) 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=@kernel.org header.s=default header.b=HUMu9TgX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732303AbeKLJzT (ORCPT + 99 others); Mon, 12 Nov 2018 04:55:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:34210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731979AbeKLIRp (ORCPT ); Mon, 12 Nov 2018 03:17:45 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3FFF22154B; Sun, 11 Nov 2018 22:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975269; bh=r0kg3B0Uo8ZaOAL44hVNNqDQxtzHqZwomQafmFLwY18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUMu9TgXzvgFemcw8kTtjhtbw5J5NICeO8OJwlR6VwLb/twAl3GdQyIiKtDckaQsh kYb3+U+Re87huVrUSsW4Zf4dKHQq95vW1+z4oEjvGR5XNodEz5GoF8ufmRK78MzOAB 7LukR0k7+QSNfxrs3tWcmWFosSKhEpnBQEFIO4Rw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Dan Williams , Sasha Levin Subject: [PATCH 4.19 139/361] UAPI: ndctl: Fix g++-unsupported initialisation in headers Date: Sun, 11 Nov 2018 14:18:06 -0800 Message-Id: <20181111221639.987942550@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Howells [ Upstream commit 9607871f37dc3e717639694b8d0dc738f2a68efc ] 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 Signed-off-by: Dan Williams Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/ndctl.h | 48 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) --- a/include/uapi/linux/ndctl.h +++ b/include/uapi/linux/ndctl.h @@ -128,37 +128,31 @@ enum { 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"; + switch (cmd) { + case ND_CMD_ARS_CAP: return "ars_cap"; + case ND_CMD_ARS_START: return "ars_start"; + case ND_CMD_ARS_STATUS: return "ars_status"; + case ND_CMD_CLEAR_ERROR: return "clear_error"; + case ND_CMD_CALL: return "cmd_call"; + default: return "unknown"; + } } static inline const char *nvdimm_cmd_name(unsigned cmd) { - static const char * const names[] = { - [ND_CMD_SMART] = "smart", - [ND_CMD_SMART_THRESHOLD] = "smart_thresh", - [ND_CMD_DIMM_FLAGS] = "flags", - [ND_CMD_GET_CONFIG_SIZE] = "get_size", - [ND_CMD_GET_CONFIG_DATA] = "get_data", - [ND_CMD_SET_CONFIG_DATA] = "set_data", - [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size", - [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log", - [ND_CMD_VENDOR] = "vendor", - [ND_CMD_CALL] = "cmd_call", - }; - - if (cmd < ARRAY_SIZE(names) && names[cmd]) - return names[cmd]; - return "unknown"; + switch (cmd) { + case ND_CMD_SMART: return "smart"; + case ND_CMD_SMART_THRESHOLD: return "smart_thresh"; + case ND_CMD_DIMM_FLAGS: return "flags"; + case ND_CMD_GET_CONFIG_SIZE: return "get_size"; + case ND_CMD_GET_CONFIG_DATA: return "get_data"; + case ND_CMD_SET_CONFIG_DATA: return "set_data"; + case ND_CMD_VENDOR_EFFECT_LOG_SIZE: return "effect_size"; + case ND_CMD_VENDOR_EFFECT_LOG: return "effect_log"; + case ND_CMD_VENDOR: return "vendor"; + case ND_CMD_CALL: return "cmd_call"; + default: return "unknown"; + } } #define ND_IOCTL 'N'