From patchwork Fri Oct 11 23:07:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4868C1668 for ; Fri, 11 Oct 2019 23:08:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 293B5218AC for ; Fri, 11 Oct 2019 23:08:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kHiz8ZzA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbfJKXH1 (ORCPT ); Fri, 11 Oct 2019 19:07:27 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34351 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfJKXH1 (ORCPT ); Fri, 11 Oct 2019 19:07:27 -0400 Received: by mail-pl1-f195.google.com with SMTP id k7so5132192pll.1; Fri, 11 Oct 2019 16:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/kC26ffR+trBknrfzrjK9Qw6ONsmCGAuEKQl7xYThEA=; b=kHiz8ZzAOitA6k2P2pLSfizpmXcvpgQR36t1m18tG+e4PWi1yiaolf1pUIuVjAUpTN aeFoP7zdeKOVs8btF7tYPoG3mrvsEWnzQA6gefaJznd5pn4IFkQT8di2dQrZzfeAAf9f hYLaSI3WhqiMeisVhNPtJqZSRgdDhXDsE49qqii2GHwHz+2fYzV1pPiqGgg+gNQpd3AM wdD1dejcilNH5FRK7VSuU6TTDM6pmdtO9THkMEYYrHgU4AcbeHdRL3uSu9UTIhM3UGzh Er4mQTIv0sFfqrKkTyl3KOeJB8rf4DBxK52FY5WFWeEdGVmPbODbtu8nU+M/WpJTbyrm N0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/kC26ffR+trBknrfzrjK9Qw6ONsmCGAuEKQl7xYThEA=; b=hhmd3WeWaG+r0cydxJP+ALSQ8bGWUjClgi/SnbrFQBr4RXiGtyxnff11yMc2allwqQ kQjtLkzvqMrqbKwoKaiPxbvK2O1dLxBan+zPgTkrwCPUf+ORh5sOYqWwauaqs3sgGyBb 2Fa5eCLqw/CoUJMBj4sQCLyfp/+1lj/t4DyXGpg/YSpRRPbQWpq+WycwYfZlkjHt0eDB MbCwFD4gmJxKHCNYzrtuvGgW1WOxcap9BK70bQB+VijJe0Ey8SoJfODLDUCSvm1+xxQ7 MI+3qWLg+CF5hkSpqwZiJm0sdpUnjhqwmUmeg6YLWUR0npSotmZLGfpBmyb47QCK+HsC yhOA== X-Gm-Message-State: APjAAAWARrhyb3Y3agZHZGLY0R84711rFg0iHKsYMvouU9hpP0GUKM7c gNYd5qFgYNkYkgtreMbfhNw= X-Google-Smtp-Source: APXvYqwJyc3CfgPlSum7I4t2L2RB4PO1jhsjwNn7JanaFSEtmoK7glcsV8KGSwXixMezhYZCh0qdVg== X-Received: by 2002:a17:902:a610:: with SMTP id u16mr17682886plq.200.1570835246462; Fri, 11 Oct 2019 16:07:26 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:25 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 01/14] software node: remove DEV_PROP_MAX Date: Fri, 11 Oct 2019 16:07:08 -0700 Message-Id: <20191011230721.206646-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org This definition is not used anywhere, let's remove it. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/property.h b/include/linux/property.h index 9b3d4ca3a73a..44c1704f7163 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -22,7 +22,6 @@ enum dev_prop_type { DEV_PROP_U32, DEV_PROP_U64, DEV_PROP_STRING, - DEV_PROP_MAX, }; enum dev_dma_attr { From patchwork Fri Oct 11 23:07:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A052417D4 for ; Fri, 11 Oct 2019 23:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 782FD214E0 for ; Fri, 11 Oct 2019 23:07:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZD9vEh8g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727399AbfJKXH3 (ORCPT ); Fri, 11 Oct 2019 19:07:29 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34396 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfJKXH2 (ORCPT ); Fri, 11 Oct 2019 19:07:28 -0400 Received: by mail-pf1-f195.google.com with SMTP id b128so6943580pfa.1; Fri, 11 Oct 2019 16:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lT2gdQyjp1sZtsGK/c5q0z/d1jVgKn5OQ6k2qAgpVco=; b=ZD9vEh8g78CR+rwyuhgYTdu+267riPbETM2kgP4gMcGDVaPA8qYVxS3RZ88yNgnwfq jWxmnjiK0aK94aeVGTdoo6N5H1qWBEnLg7arpONYqKh1k0gts0mUHgdypxMplT3alSRH +8UohxmpNKU5RovPhzcCK1AabW6sQRFcC+nVsUgSoDWLQVmo+PmLQVd59tiSHOH81Z6e XWXBGG0bS/dY5QBRUYNV8udhmy6lGqciEBL4sTUO7mQkGKnwO3UlhcCBuj36cut/ZESZ WADo3RmqisGwoV3LxobG4D54rAVnBIhM7c6yERYz4WV6xa49zslacM7mn1BhG35V4Z/K 0U9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lT2gdQyjp1sZtsGK/c5q0z/d1jVgKn5OQ6k2qAgpVco=; b=ekQyMWaudQlK+48xt9eXguxV+BMtis4Kqza5BnmhySwRKBu+lfbbHsUDeCCdvpoZrq yT1ZqqMS+pTPEYkRk0XYBSY4ZQEPaMzdqT4NI9FAOe1hGYzwotrGux5gZ8IOV1ymKM+s jyTd9RZkt5q4BeT6JCKOLrCBs1sMv9+pf7vM5Km57IkKrHCpsTW10Mo7NUADhAChy7ag Q7eKTpZurVQS38UlCnQktW2pS2Xckc+NAN5B8+2ydmijM4RyMvpAUcIH7CqIrgGoJsmP JttRIFPC5R3ksDKlay2+h6J6gFERloiKYlXOlSLt6mY7eNd7WY0/POEPgIqbgFj7e0/V 1LGw== X-Gm-Message-State: APjAAAWmfjxvpPzoM0DedR66vrs2tyb92A2GRY2f/IVwpc1WtnNGU+QE zogWrD/nyH/9u9naFczpsc4= X-Google-Smtp-Source: APXvYqwOuJaftQtLj0GEpLf419ArNk3YVlmp0/3HCXM+AfFiGEjrLjZ4Nk6STb3b7NnfUPdEv9oTwA== X-Received: by 2002:a63:2d43:: with SMTP id t64mr19301047pgt.428.1570835247330; Fri, 11 Oct 2019 16:07:27 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:26 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 02/14] software node: introduce PROPERTY_ENTRY_ARRAY_XXX_LEN() Date: Fri, 11 Oct 2019 16:07:09 -0700 Message-Id: <20191011230721.206646-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Sometimes we want to initialize property entry array from a regular pointer, when we can't determine length automatically via ARRAY_SIZE. Let's introduce PROPERTY_ENTRY_ARRAY_XXX_LEN macros that take explicit "len" argument. Signed-off-by: Dmitry Torokhov Reviewed-by: Andy Shevchenko --- include/linux/property.h | 45 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index 44c1704f7163..f89b930ca4b7 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -256,33 +256,44 @@ struct property_entry { * and structs. */ -#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \ +#define PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_) \ (struct property_entry) { \ .name = _name_, \ - .length = ARRAY_SIZE(_val_) * sizeof(_type_), \ + .length = (_len_) * sizeof(_type_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = { ._type_##_data = _val_ } }, \ } -#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, U8, _val_) -#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, U16, _val_) -#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, U32, _val_) -#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, U64, _val_) +#define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) +#define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) +#define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) +#define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) -#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = ARRAY_SIZE(_val_) * sizeof(const char *), \ - .is_array = true, \ - .type = DEV_PROP_STRING, \ - { .pointer = { .str = _val_ } }, \ +#define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = (_len_) * sizeof(const char *), \ + .is_array = true, \ + .type = DEV_PROP_STRING, \ + { .pointer = { .str = _val_ } }, \ } +#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) + #define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ From patchwork Fri Oct 11 23:07:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C896A1668 for ; Fri, 11 Oct 2019 23:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A93BE214E0 for ; Fri, 11 Oct 2019 23:07:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hTrk6+YG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727507AbfJKXHa (ORCPT ); Fri, 11 Oct 2019 19:07:30 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36712 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfJKXHa (ORCPT ); Fri, 11 Oct 2019 19:07:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id j11so5124475plk.3; Fri, 11 Oct 2019 16:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ZYLBJ+D5Yj2TyAfqtVnlRP+o58MbtxtSvNW0pAxio0=; b=hTrk6+YGPAqylfdKEerSa+ZRY2Ne82nAftfgJuTKOWk4GqVp2Liuc2dkH8aOxVFh0U RrZjQS7NGkyHIN5tcWkk6P3X8632ZKCveKPMYnCQZP0chhfoi/4wz3Q/uhkNeuujm8Ry ocg4aqwgAyGRnBuuvC3RVkJPKzWUT72F50fe1BaExwU0esuOHWovReSYGyHQ063Xgu0B 8vZ5ANJn+fJhO9Rb1BjirE5kkJK7gT1AL91L2H1tvRdOIrzxpJrep69VuQYKEl+hbY4I ZzIHbvvZo+iSmdkNsXpBEkUVX+zV35fiuRQX7nMbNW3D4SJxrWsW+P55EPikqc/+kiEw EoqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ZYLBJ+D5Yj2TyAfqtVnlRP+o58MbtxtSvNW0pAxio0=; b=BFWG1FaouTayV5xSImzrvJd0uRwnZz/nqIJnjDczmc2lDlYBOYYTkUSp1SfdbCHdXS FWWclACSbnLMGMghkSIwo5R1y9vwN3i2d6YelGB8frqtbb8QE81RAWj5WZftYWndBiIK 8eEJRFcK+Opl6xE/osoKH5ZiMsOJS20SVEXk9i/diisgSfnwmYyo7cNG/qmXVuDPuP5+ fOAcFyZo0jf46ZW3zTUjrxHf8SQ3Qpuw1WZlv0cWKDlUi288tLywwQEi6nfazAPWL43f Q2SFCkAgz47WsDwPZX22gr2MyyFGdlL7UFDoo6PBvaq++hLpRF4oKFTunNUA2VfzOM4v tbXw== X-Gm-Message-State: APjAAAUMJ6iQs1y3FtpbUkPe9UP4+IzqZiaU1g6GU4mFD3bgFuwB8nyC 95wK9q+ZDgOoKz0KMleVHRo= X-Google-Smtp-Source: APXvYqz0sE40S0sxerzvSuQRl1sFjwso291GXoC7W9EDm1ObN7O14wMQ/eBUQ0R6R3REAPzD5qjVsg== X-Received: by 2002:a17:902:76c4:: with SMTP id j4mr15570685plt.9.1570835249225; Fri, 11 Oct 2019 16:07:29 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:27 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 03/14] efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN Date: Fri, 11 Oct 2019 16:07:10 -0700 Message-Id: <20191011230721.206646-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Let's switch to using PROPERTY_ENTRY_U8_ARRAY_LEN() to initialize property entries. Also, when dumping data, rely on local variables instead of poking into the property entry structure directly. Signed-off-by: Dmitry Torokhov Reviewed-by: Andy Shevchenko --- drivers/firmware/efi/apple-properties.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c index 0e206c9e0d7a..5ccf39986a14 100644 --- a/drivers/firmware/efi/apple-properties.c +++ b/drivers/firmware/efi/apple-properties.c @@ -53,7 +53,8 @@ static void __init unmarshal_key_value_pairs(struct dev_header *dev_header, for (i = 0; i < dev_header->prop_count; i++) { int remaining = dev_header->len - (ptr - (void *)dev_header); - u32 key_len, val_len; + u32 key_len, val_len, entry_len; + const u8 *entry_data; char *key; if (sizeof(key_len) > remaining) @@ -85,17 +86,14 @@ static void __init unmarshal_key_value_pairs(struct dev_header *dev_header, ucs2_as_utf8(key, ptr + sizeof(key_len), key_len - sizeof(key_len)); - entry[i].name = key; - entry[i].length = val_len - sizeof(val_len); - entry[i].is_array = !!entry[i].length; - entry[i].type = DEV_PROP_U8; - entry[i].pointer.u8_data = ptr + key_len + sizeof(val_len); - + entry_data = ptr + key_len + sizeof(val_len); + entry_len = val_len - sizeof(val_len); + entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data, + entry_len); if (dump_properties) { - dev_info(dev, "property: %s\n", entry[i].name); + dev_info(dev, "property: %s\n", key); print_hex_dump(KERN_INFO, pr_fmt(), DUMP_PREFIX_OFFSET, - 16, 1, entry[i].pointer.u8_data, - entry[i].length, true); + 16, 1, entry_data, entry_len, true); } ptr += key_len + val_len; From patchwork Fri Oct 11 23:07:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC8941668 for ; Fri, 11 Oct 2019 23:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD658218AC for ; Fri, 11 Oct 2019 23:08:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W4AAfAQn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbfJKXHc (ORCPT ); Fri, 11 Oct 2019 19:07:32 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:32813 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727525AbfJKXHb (ORCPT ); Fri, 11 Oct 2019 19:07:31 -0400 Received: by mail-pg1-f195.google.com with SMTP id i76so6619871pgc.0; Fri, 11 Oct 2019 16:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RnKvYYIsaWzXDiXUGcpFyytv3QO7fUH3tnXfDULVuBw=; b=W4AAfAQn/IONg/xV4fI08ZaOEFyRF3bJEtfRXmzLbdEgHEazSpcurduTRhObKpnaQ5 nKUGu/bDuwS6Di8uvVtDjwCAJpFKPDcZSWlo5wwQFKTT5RcN4nOfTAzufh94RwhenE6w 1TrnExvm7DizeqA18j/vGyg7WaL0/3XmKuVULwHJ+C8WhuPHLaz5BJY3axZrBbmI93Sf jugPKOFF1eeUNTvjFRP7gkDXDjt6d8jhtm6VKW7TKXAUbcJnBESdzkEUwVqPLsbk4eYo LS2DVCWvMNjYnv9QuEfwUktBvuYG10oym1nOgz1CDlvdn2CEb79iDn3Dg94km5C35F2m mgew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RnKvYYIsaWzXDiXUGcpFyytv3QO7fUH3tnXfDULVuBw=; b=QM7y+Qawc3/1WfVVsJ+80rB3aHs9LsOfO4MtpxLIMDf9nhDIEF7rWLhdklAGBrb2aL S3E/rI9ciy+ma2UWMhCUnvU1Lzls3ylS9rD7598ZmQ2be/qOjSc48lyI562csdp8sj8w l5HjPGf7tRK+aqrGbJWA/okqcbFhp+sEohD+82s405QG1rVPLAQlFtDXFZYGu26CTLVZ Bcezo9k+MC2k+wWYy/DyZLz677xp2LE3y2pDsKaUWf6K73ujkJ0DEap713NzrXthyOgC dkf2CZ/gSXoAAwLaMkLnKREYbP4yd8/SBPXIGixd8frXhiXnmb7y98rFKp/qOAP7y9Qz LuhQ== X-Gm-Message-State: APjAAAUSFErHei+JsjP4w223R8DniREE6jvc4iZrD+ScvCSThYh8ZZJo KtXpliNhfqfhUSJOCHgtH1UNvd9n X-Google-Smtp-Source: APXvYqzvCMJ0Ij7Od1pT0+Xdf7FUEY5b5xcIKSO/ARlH0HY6u8tKlSXnvpPSFi6F3BLrDETbqjSY1g== X-Received: by 2002:a63:a054:: with SMTP id u20mr7118066pgn.313.1570835250144; Fri, 11 Oct 2019 16:07:30 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:29 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 04/14] software node: mark internal macros with double underscores Date: Fri, 11 Oct 2019 16:07:11 -0700 Message-Id: <20191011230721.206646-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Let's mark PROPERTY_ENTRY_* macros that are internal with double leading underscores so users are not tempted to use them. Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index f89b930ca4b7..2c9d4d209296 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -256,7 +256,7 @@ struct property_entry { * and structs. */ -#define PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_) \ +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_)\ (struct property_entry) { \ .name = _name_, \ .length = (_len_) * sizeof(_type_), \ @@ -266,13 +266,13 @@ struct property_entry { } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ (struct property_entry) { \ @@ -294,7 +294,7 @@ struct property_entry { #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) -#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ +#define __PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ .length = sizeof(_type_), \ @@ -303,13 +303,13 @@ struct property_entry { } #define PROPERTY_ENTRY_U8(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) #define PROPERTY_ENTRY_U16(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) #define PROPERTY_ENTRY_U32(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) #define PROPERTY_ENTRY_U64(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) #define PROPERTY_ENTRY_STRING(_name_, _val_) \ (struct property_entry) { \ From patchwork Fri Oct 11 23:07:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0655218B7 for ; Fri, 11 Oct 2019 23:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1CD5214E0 for ; Fri, 11 Oct 2019 23:07:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Eo8QuNDS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727856AbfJKXHd (ORCPT ); Fri, 11 Oct 2019 19:07:33 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39828 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727842AbfJKXHd (ORCPT ); Fri, 11 Oct 2019 19:07:33 -0400 Received: by mail-pl1-f193.google.com with SMTP id s17so5114066plp.6; Fri, 11 Oct 2019 16:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YCedBuQFpwmyDfQI6sD+E2lALu5XRSGZTBcPHifNSjo=; b=Eo8QuNDSRErj1fkPFFHRRByLpevbKrPFuVOYzhXDMX5ggCV+KO430KQODe+4jo5em2 Uxf5cawMvb1jnAP1ECoi+ExeHfD3g+1YlwJbl8UZC5U4e0Hxu4tb9w4KxTwJvwD+ogWD qp2U+riefnvWNyHCgTYih9rRLBkd6mTb9znu2YTPYs0TV7kmohMa4pR3QnAEHwFbx/Gz aPz3UDSxV78hvwXH8rw/THElQ6kSyiv4iYBWeSHtevlTo3p6CiqIkOHZcsUxBKRjSD2m sGwsISyq3VEQ5TN6tBZn8hjxqqE7RSrZqxwprk8ThlzmBOeKC5jS54iBxLYujUcNuCWe 6SRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YCedBuQFpwmyDfQI6sD+E2lALu5XRSGZTBcPHifNSjo=; b=Neh7nVhdSz/6hAfR6juIAAIFV4s1jVaTkNf5aB6X/blXm6rgu7Cg2cZlxlbZaleqKV 3Syz56myXUO7ujk58pVZdfYw2IUw77qTMDvqZVuQ4TppYA4P90AioEDcqDRZh1O8Kfuy XYkofElDY6L6H53bu/lgarVTx+8/aLPaaIP5DVgTxfQIer7RwEfF2XfUCf7ghzkk5AiT +ReuXHFp/Lu4c35BBDl/3sOdZpS+GachaG4SoZlHowMvAqHpCPz0M46CX0e5SCuqfG7A FqDbHEpY98H44WszEyhbIAEHrLncFgr1kMhpsi4U7Z1Lu4e7Iw97MemVs3gtePe8DLkg ia7A== X-Gm-Message-State: APjAAAU1TsGl0XqYrVv5GNOC67m/ZVOeGbwoOvMwu0gXlGP6QItXowry TUfZ5bKP+eF+iR7p7e4S5o0= X-Google-Smtp-Source: APXvYqyhNyzlkmmr4MdraRLNF6qI3ydH/9oHqlY3spU3yF1i+RDYZDiEU9vcmm8cDSb7XGitxqDvKg== X-Received: by 2002:a17:902:ac8a:: with SMTP id h10mr17051503plr.180.1570835252032; Fri, 11 Oct 2019 16:07:32 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:30 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 05/14] software node: clean up property_copy_string_array() Date: Fri, 11 Oct 2019 16:07:12 -0700 Message-Id: <20191011230721.206646-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Because property_copy_string_array() stores the newly allocated pointer in the destination property, we have an awkward code in property_entry_copy_data() where we fetch the new pointer from dst. Let's change property_copy_string_array() to return pointer and rely on the common path in property_entry_copy_data() to store it in destination structure. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index a1f3f0994f9f..2f2248c9003c 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -337,8 +337,8 @@ static void property_entry_free_data(const struct property_entry *p) kfree(p->name); } -static int property_copy_string_array(struct property_entry *dst, - const struct property_entry *src) +static const char * const * +property_copy_string_array(const struct property_entry *src) { const char **d; size_t nval = src->length / sizeof(*d); @@ -346,7 +346,7 @@ static int property_copy_string_array(struct property_entry *dst, d = kcalloc(nval, sizeof(*d), GFP_KERNEL); if (!d) - return -ENOMEM; + return NULL; for (i = 0; i < nval; i++) { d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); @@ -354,12 +354,11 @@ static int property_copy_string_array(struct property_entry *dst, while (--i >= 0) kfree(d[i]); kfree(d); - return -ENOMEM; + return NULL; } } - dst->pointer.str = d; - return 0; + return d; } static int property_entry_copy_data(struct property_entry *dst, @@ -367,17 +366,15 @@ static int property_entry_copy_data(struct property_entry *dst, { const void *pointer = property_get_pointer(src); const void *new; - int error; if (src->is_array) { if (!src->length) return -ENODATA; if (src->type == DEV_PROP_STRING) { - error = property_copy_string_array(dst, src); - if (error) - return error; - new = dst->pointer.str; + new = property_copy_string_array(src); + if (!new) + return -ENOMEM; } else { new = kmemdup(pointer, src->length, GFP_KERNEL); if (!new) From patchwork Fri Oct 11 23:07:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88FCE17EE for ; Fri, 11 Oct 2019 23:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61AAD218AC for ; Fri, 11 Oct 2019 23:08:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KMxWNbzN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728537AbfJKXIO (ORCPT ); Fri, 11 Oct 2019 19:08:14 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39198 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727842AbfJKXHg (ORCPT ); Fri, 11 Oct 2019 19:07:36 -0400 Received: by mail-pf1-f196.google.com with SMTP id v4so6927070pff.6; Fri, 11 Oct 2019 16:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=My6TZcxC7HEAgtz1q11BSr9nCjfXFfYRNGIk6rK3DR8=; b=KMxWNbzN6cc4mzi8RIjo4WOOYEC9N+ZWptP0f1TmXpWJkmKiwuVJ5+IxDPaJKQLV4W TIyHSYXL/ZOe1WSleVes5nyLcTUd8HKtw/SP5+gyj11b85yL/hfrO0ONZoR93HV39Ajh W7g1lxTC0TSPwuAtKU6E/v8nD000uVDVPYN6G2phE5pCY0tziFbSY2dZdh+79oBsMibF oTfOSui/snG+yR3tB+Z8I81k2DlTFGcRCNUS4GbgwgNc83mO0FSRou9BndrVw4mMoYmO /MfBP3gUij2s1vk+MfhtRCAD07VlHReb83ox0AsPHcT6oM9GB67ruRxlOfAxy+YmOK/4 GWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=My6TZcxC7HEAgtz1q11BSr9nCjfXFfYRNGIk6rK3DR8=; b=Tb9+X35zHaBPhiFs1m9LS7QJF6mJhJLnnqB6LQOiUmbgatiOsIEfgYCBiwrDKk8unX ucc9Q0VxiJ0N8kMsjB95kmt2MD1oE+pvZp28ywP5fGToRpCGdSeJG3AZj9/156WjiI8e /rxFktbk+RghEMFmXWIiCL5qpOHbqNNkcVqaGKLZxZB4FG2DXRALbNdXSoSpyj/NeNZq vByy8KvnwODbEo3BoE2J0ENIU8DybB727mP1fIo6CPKl1IdNmxOPJjYTDTz8pIPJ9nPV P9/kqol+FbRIpQl9iLfHTIC115ikHKhPetGR9AIZWLh7fGaLBAu57jyPHX8WEgp97iy7 rXaA== X-Gm-Message-State: APjAAAVUjTLGmcv01pLzeP5S4+lMxMeaO9xoQ8t2ej4QtN8nAKmIm3R6 Hnep9Nd0iKabP9xVr6eUzOfmtzOg X-Google-Smtp-Source: APXvYqx0GB8ADH7HX/DLbxeuorogn2V/yCFho8ZLh2gZEm7CW65hDZlYRdCRM6YRc9SbKPISI+G2pA== X-Received: by 2002:a65:400b:: with SMTP id f11mr19640569pgp.57.1570835254077; Fri, 11 Oct 2019 16:07:34 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:32 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 06/14] software node: get rid of property_set_pointer() Date: Fri, 11 Oct 2019 16:07:13 -0700 Message-Id: <20191011230721.206646-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Instead of explicitly setting values of integer types when copying property entries lets just copy entire value union when processing non-array values. For value arrays we no longer use union of pointers, but rather a single void pointer, which allows us to remove property_set_pointer(). In property_get_pointer() we do not need to handle each data type separately, we can simply return either the pointer or pointer to values union. We are not losing anything from removing typed pointer union because the upper layers do their accesses through void pointers anyway, and we trust the "type" of the property when interpret the data. We rely on users of property entries on using PROPERTY_ENTRY_XXX() macros to properly initialize entries instead of poking in the instances directly. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 90 +++++++++------------------------------- include/linux/property.h | 12 ++---- 2 files changed, 22 insertions(+), 80 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 2f2248c9003c..26e56dd66436 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -103,71 +103,15 @@ property_entry_get(const struct property_entry *prop, const char *name) return NULL; } -static void -property_set_pointer(struct property_entry *prop, const void *pointer) -{ - switch (prop->type) { - case DEV_PROP_U8: - if (prop->is_array) - prop->pointer.u8_data = pointer; - else - prop->value.u8_data = *((u8 *)pointer); - break; - case DEV_PROP_U16: - if (prop->is_array) - prop->pointer.u16_data = pointer; - else - prop->value.u16_data = *((u16 *)pointer); - break; - case DEV_PROP_U32: - if (prop->is_array) - prop->pointer.u32_data = pointer; - else - prop->value.u32_data = *((u32 *)pointer); - break; - case DEV_PROP_U64: - if (prop->is_array) - prop->pointer.u64_data = pointer; - else - prop->value.u64_data = *((u64 *)pointer); - break; - case DEV_PROP_STRING: - if (prop->is_array) - prop->pointer.str = pointer; - else - prop->value.str = pointer; - break; - default: - break; - } -} - static const void *property_get_pointer(const struct property_entry *prop) { - switch (prop->type) { - case DEV_PROP_U8: - if (prop->is_array) - return prop->pointer.u8_data; - return &prop->value.u8_data; - case DEV_PROP_U16: - if (prop->is_array) - return prop->pointer.u16_data; - return &prop->value.u16_data; - case DEV_PROP_U32: - if (prop->is_array) - return prop->pointer.u32_data; - return &prop->value.u32_data; - case DEV_PROP_U64: - if (prop->is_array) - return prop->pointer.u64_data; - return &prop->value.u64_data; - case DEV_PROP_STRING: - if (prop->is_array) - return prop->pointer.str; - return &prop->value.str; - default: + if (!prop->length) return NULL; - } + + if (prop->is_array) + return prop->pointer; + + return &prop->value; } static const void *property_entry_find(const struct property_entry *props, @@ -322,13 +266,15 @@ static int property_entry_read_string_array(const struct property_entry *props, static void property_entry_free_data(const struct property_entry *p) { const void *pointer = property_get_pointer(p); + const char * const *src_str; size_t i, nval; if (p->is_array) { - if (p->type == DEV_PROP_STRING && p->pointer.str) { + if (p->type == DEV_PROP_STRING && p->pointer) { + src_str = p->pointer; nval = p->length / sizeof(const char *); for (i = 0; i < nval; i++) - kfree(p->pointer.str[i]); + kfree(src_str[i]); } kfree(pointer); } else if (p->type == DEV_PROP_STRING) { @@ -341,6 +287,7 @@ static const char * const * property_copy_string_array(const struct property_entry *src) { const char **d; + const char * const *src_str = src->pointer; size_t nval = src->length / sizeof(*d); int i; @@ -349,8 +296,8 @@ property_copy_string_array(const struct property_entry *src) return NULL; for (i = 0; i < nval; i++) { - d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); - if (!d[i] && src->pointer.str[i]) { + d[i] = kstrdup(src_str[i], GFP_KERNEL); + if (!d[i] && src_str[i]) { while (--i >= 0) kfree(d[i]); kfree(d); @@ -380,20 +327,21 @@ static int property_entry_copy_data(struct property_entry *dst, if (!new) return -ENOMEM; } + + dst->is_array = true; + dst->pointer = new; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) return -ENOMEM; + + dst->value.str = new; } else { - new = pointer; + dst->value = src->value; } dst->length = src->length; - dst->is_array = src->is_array; dst->type = src->type; - - property_set_pointer(dst, new); - dst->name = kstrdup(src->name, GFP_KERNEL); if (!dst->name) goto out_free_data; diff --git a/include/linux/property.h b/include/linux/property.h index 2c9d4d209296..ec8f84d564a8 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -233,13 +233,7 @@ struct property_entry { bool is_array; enum dev_prop_type type; union { - union { - const u8 *u8_data; - const u16 *u16_data; - const u32 *u32_data; - const u64 *u64_data; - const char * const *str; - } pointer; + const void *pointer; union { u8 u8_data; u16 u16_data; @@ -262,7 +256,7 @@ struct property_entry { .length = (_len_) * sizeof(_type_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ - { .pointer = { ._type_##_data = _val_ } }, \ + { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ @@ -280,7 +274,7 @@ struct property_entry { .length = (_len_) * sizeof(const char *), \ .is_array = true, \ .type = DEV_PROP_STRING, \ - { .pointer = { .str = _val_ } }, \ + { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ From patchwork Fri Oct 11 23:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C131E1668 for ; Fri, 11 Oct 2019 23:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A76221A4A for ; Fri, 11 Oct 2019 23:07:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="maj1rsW1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728053AbfJKXHh (ORCPT ); Fri, 11 Oct 2019 19:07:37 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35294 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728000AbfJKXHg (ORCPT ); Fri, 11 Oct 2019 19:07:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id p30so6616394pgl.2; Fri, 11 Oct 2019 16:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oWfZp87EtAgwEM99H5cVmirzQT+GLNapRRUGkPZCCcQ=; b=maj1rsW1SHL/7fpICwUugPUkcrd25Ok67/NPn1kiG54zeH1pT3janfocb+bVme1dZ3 1vM6Q7d9jS9abmDwG//vQeH2J97IHa10GK6Pk9k2u1fo0M068+fog5OoxcTpGrO7ZnpB nzev+K2NqRbTwNIb4cXZ2tZdQNY7JvVF/qrP5yypcAvR6iUJUy/8mm0/tH0OWKt9ttAP 5r4AoDrNLBKhCYPMLhI0RiJVaRrV9UzY9M8XYzpAlQdTfOi0TgW3H9mXJkWgbj80V8eD NaE3nB+wBiZg1l/WHFZ2qSKYvsznVdoVLHWWFXZ+q1+AoxqKzElVm158ez2r4/WIcEAc xcEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oWfZp87EtAgwEM99H5cVmirzQT+GLNapRRUGkPZCCcQ=; b=O3k8pcMR9VLMOJePohoT4jlrjiNj1jQ8So0cXJT2uNVhFeAM48ZfJBipAPiruuGdZA 90U5wN4qAy2vAmAYhTC8nvKzxev84zE4BE8tiw7jxFI9yP8mbIXosZ3KaxXu3DFa+Be3 Zd0+AyMMlnx+tdYyHEaRKr70s229x69c4vwET4MW04oAHFFKuPEMwogWDSVvgIy1NBam kg6HzY0uwEpuelYCQVJ4PQ24mlNebYnc2WNeaHt4qNhaEqkAJrYZc5+6bfkVACtlUlmp IpQaEiD4mWGao+8Q1hWDrflGakTjT5O8Cf/tXp1LtKsbUHFaNdVGhFIv5EEa1GKgBwmh br/Q== X-Gm-Message-State: APjAAAV/ZtQjh6805CH3Tl+20xUzHP+/9BTmcWWI34vh96Dmyk18M386 91+QV6INI/7mRBLrbMQ9sW0= X-Google-Smtp-Source: APXvYqxGfnL+uQASCHlvc4dCdVgFvfqkoA2EKj5FnIYzlhIdRhmjWbbQ1tMJQhHm792CXqcQNmjZeg== X-Received: by 2002:a63:4525:: with SMTP id s37mr17014276pga.148.1570835255009; Fri, 11 Oct 2019 16:07:35 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:34 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 07/14] software node: remove property_entry_read_uNN_array functions Date: Fri, 11 Oct 2019 16:07:14 -0700 Message-Id: <20191011230721.206646-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org There is absolutely no reason to have them as we can handle it all nicely in property_entry_read_int_array(). Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 85 +++++++------------------------------------ 1 file changed, 14 insertions(+), 71 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 26e56dd66436..b11cc4dbff08 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -131,66 +131,6 @@ static const void *property_entry_find(const struct property_entry *props, return pointer; } -static int property_entry_read_u8_array(const struct property_entry *props, - const char *propname, - u8 *values, size_t nval) -{ - const void *pointer; - size_t length = nval * sizeof(*values); - - pointer = property_entry_find(props, propname, length); - if (IS_ERR(pointer)) - return PTR_ERR(pointer); - - memcpy(values, pointer, length); - return 0; -} - -static int property_entry_read_u16_array(const struct property_entry *props, - const char *propname, - u16 *values, size_t nval) -{ - const void *pointer; - size_t length = nval * sizeof(*values); - - pointer = property_entry_find(props, propname, length); - if (IS_ERR(pointer)) - return PTR_ERR(pointer); - - memcpy(values, pointer, length); - return 0; -} - -static int property_entry_read_u32_array(const struct property_entry *props, - const char *propname, - u32 *values, size_t nval) -{ - const void *pointer; - size_t length = nval * sizeof(*values); - - pointer = property_entry_find(props, propname, length); - if (IS_ERR(pointer)) - return PTR_ERR(pointer); - - memcpy(values, pointer, length); - return 0; -} - -static int property_entry_read_u64_array(const struct property_entry *props, - const char *propname, - u64 *values, size_t nval) -{ - const void *pointer; - size_t length = nval * sizeof(*values); - - pointer = property_entry_find(props, propname, length); - if (IS_ERR(pointer)) - return PTR_ERR(pointer); - - memcpy(values, pointer, length); - return 0; -} - static int property_entry_count_elems_of_size(const struct property_entry *props, const char *propname, size_t length) @@ -209,21 +149,24 @@ static int property_entry_read_int_array(const struct property_entry *props, unsigned int elem_size, void *val, size_t nval) { + const void *pointer; + size_t length; + if (!val) return property_entry_count_elems_of_size(props, name, elem_size); - switch (elem_size) { - case sizeof(u8): - return property_entry_read_u8_array(props, name, val, nval); - case sizeof(u16): - return property_entry_read_u16_array(props, name, val, nval); - case sizeof(u32): - return property_entry_read_u32_array(props, name, val, nval); - case sizeof(u64): - return property_entry_read_u64_array(props, name, val, nval); - } - return -ENXIO; + if (!is_power_of_2(elem_size) || elem_size > sizeof(u64)) + return -ENXIO; + + length = nval * elem_size; + + pointer = property_entry_find(props, name, length); + if (IS_ERR(pointer)) + return PTR_ERR(pointer); + + memcpy(val, pointer, length); + return 0; } static int property_entry_read_string_array(const struct property_entry *props, From patchwork Fri Oct 11 23:07:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F366317D4 for ; Fri, 11 Oct 2019 23:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBB41218AC for ; Fri, 11 Oct 2019 23:08:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JRnPoZdp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728080AbfJKXIJ (ORCPT ); Fri, 11 Oct 2019 19:08:09 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45189 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728009AbfJKXHh (ORCPT ); Fri, 11 Oct 2019 19:07:37 -0400 Received: by mail-pg1-f195.google.com with SMTP id r1so5412038pgj.12; Fri, 11 Oct 2019 16:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OqjVMmiDxfmWkTPNKFCbYpwJz27qwBGl/ZyazByuYTo=; b=JRnPoZdpObClmVOztYVeJ8IqwldxKRkV+F+19NBbFBwDUh9vtyM0+wFOw5veBv3cBF 3f1y7wVNXynYYanRJOcZ3M+S0vgM/ZLvHZUppSPt/K+pIVi7p/n7L0v9XnyFMh69nw0Q Y6S0McDonX/IVWUPB6tFMWA21tUr2IgIZe9l899S7obyvtA0P6CXkVjeliDw0l2U1jCH wilmgPHRyMRBjGT0cX8y/1aVqROK6KEOY7aZqB2CikFjP+5PPPEhBaZ7nfg+OYPqszJJ Jz/su4Qc5u2czXdlMHZ6hswKD3r0a94HCtPL3qhy29kMGO/Hwc9DMJSET66+okMcL6WI f0/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OqjVMmiDxfmWkTPNKFCbYpwJz27qwBGl/ZyazByuYTo=; b=guYVt1QNO9WXKNKfshJZu28TYnLWdIwtlhHuOAOV+RU/8WzjuU30vji/o2ibYJheTZ jbnMnQRQp4NGVJhwSc9hbVd4yUodpBap64eN4BxpjiD77LwGwOCtChSC1irWgaMVSoCf Eb3tvXfJReRwi55QzMLUDZDB5v273wxZtysR4k1u+3yR48zDGeCJZKUClww6tOltlHfU ANNNmerQ29FEqSRzULo+spfuXWQU/HnWjDBfS17p0frgxuCr60tlTPsnasoIAiYG5V2N CF8IkISrWb1E8mGtJIUs1JEMRmBYR5MnaJbbmtTg32PmFzN51r3Brq9Ckt6UuTCCtIHz Bc0Q== X-Gm-Message-State: APjAAAU71VUCZnmc8JfeucT9tigrBUm/j4+aJRsI4g5WZ5X0fCf4io30 IOqcXnLzAT2+qOsDPjgLvEqMld+R X-Google-Smtp-Source: APXvYqx9kbyBMLwN3pCVvjb+MPuBzU7X2/QUuJO5QsTfWS4c6PHjKInZX81gE54gTsHZ8L2foEB6WA== X-Received: by 2002:a62:e40d:: with SMTP id r13mr19071958pfh.135.1570835256206; Fri, 11 Oct 2019 16:07:36 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:35 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 08/14] software node: unify PROPERTY_ENTRY_XXX macros Date: Fri, 11 Oct 2019 16:07:15 -0700 Message-Id: <20191011230721.206646-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org We can unify string properties initializer macros with integer initializers. Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 64 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index ec8f84d564a8..238e1507925f 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -245,37 +245,33 @@ struct property_entry { }; /* - * Note: the below four initializers for the anonymous union are carefully + * Note: the below initializers for the anonymous union are carefully * crafted to avoid gcc-4.4.4's problems with initialization of anon unions * and structs. */ -#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_)\ +#define __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_) \ + sizeof(((struct property_entry *)NULL)->value._elem_) + +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ (struct property_entry) { \ .name = _name_, \ - .length = (_len_) * sizeof(_type_), \ + .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_) #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_) #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) - + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = (_len_) * sizeof(const char *), \ - .is_array = true, \ - .type = DEV_PROP_STRING, \ - { .pointer = _val_ }, \ -} + __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) @@ -288,30 +284,24 @@ struct property_entry { #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) -#define __PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = sizeof(_type_), \ - .type = DEV_PROP_##_Type_, \ - { .value = { ._type_##_data = _val_ } }, \ +#define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .type = DEV_PROP_##_Type_, \ + { .value = { ._elem_ = _val_ } }, \ } -#define PROPERTY_ENTRY_U8(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) -#define PROPERTY_ENTRY_U16(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) -#define PROPERTY_ENTRY_U32(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) -#define PROPERTY_ENTRY_U64(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) - -#define PROPERTY_ENTRY_STRING(_name_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = sizeof(const char *), \ - .type = DEV_PROP_STRING, \ - { .value = { .str = _val_ } }, \ -} +#define PROPERTY_ENTRY_U8(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_) +#define PROPERTY_ENTRY_U16(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_) +#define PROPERTY_ENTRY_U32(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_) +#define PROPERTY_ENTRY_U64(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_) +#define PROPERTY_ENTRY_STRING(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) #define PROPERTY_ENTRY_BOOL(_name_) \ (struct property_entry) { \ From patchwork Fri Oct 11 23:07:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B4E21668 for ; Fri, 11 Oct 2019 23:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BE3C218AC for ; Fri, 11 Oct 2019 23:08:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mK1PFvgx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728111AbfJKXHj (ORCPT ); Fri, 11 Oct 2019 19:07:39 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36814 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbfJKXHi (ORCPT ); Fri, 11 Oct 2019 19:07:38 -0400 Received: by mail-pf1-f194.google.com with SMTP id y22so6929604pfr.3; Fri, 11 Oct 2019 16:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DkKt0dZ5kBaLP0Kzj2iDpOxmN4C6Vh8shX9VPkLgJ6k=; b=mK1PFvgx/69qpMXtnnM4f9aVXF4Y6Fvq9yOz+bFJFqyFCmU42kW3j/sHXrr3PnTTzM ATohWl0jQa76jlU0Q1pMEV7OjiUI8Qy1oWfghnF/nhJcAML7l+YqVt5wLkXhhmjRwdIP Iz+c9BjmJDpg8pKVXJKkioaIxaQMGirG7OP6xQ47HuLLMocew9T5mSa9xvDJj9Vt4zir CCnjLAhv2Vua2mFcYcwYi8vlkCbM87X0sYoTkUR6i0Msaai4xchoutGQMI7jki38Gv33 JmVtWMX1AksF98RcJZvXsae/A2Pt7QL8zpH+fEmLjL2sGrgIMVl5Zrxa+z2peLkZ/I0X +KnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DkKt0dZ5kBaLP0Kzj2iDpOxmN4C6Vh8shX9VPkLgJ6k=; b=KzXFR/gZEfjXQZqDQTy6lAeLLff9MgqfE6UGDoQSA0n+CuqQXaxwbjHOXV4CRUcEDU CahKo90bzoTGWzWdg/aSOo/ZX4sKeqgbZ0k2WGRXd/V1bXKeblCA0M8nK+s75BVpmYLJ yz4eLRGszv2EsVBXJiu8ECjLA9kyL9G7g/QpwP0Ooy4OIwaDVm95cINDB10vylhLNAjS PuMiDFYtTHS89/NPevwxC8vS8UYS9R2bv8NeA62QHDsDB0aOg/uDSZcnhYuKLcW1gMWx +05TdCAzfatOQ/p8W9op8tMH5BYM91Lx1sqFOzUXm3h0bbP0gANWwW9fHKkjQnor/R4Z 8yIg== X-Gm-Message-State: APjAAAUiVKXTSgPBNRpwtNMiw3oD/A1PqbJVruCf/AZ0Gucn55mCWJ64 rOm28SROLbhadPlxztcYMJo= X-Google-Smtp-Source: APXvYqymiqKMWp7iQNxQk+RDLhJlTpoi3VXlJITJ2GbhXG3GcU7UQAEzpFfMGBMxEm6yOOayi4uXKw== X-Received: by 2002:aa7:956a:: with SMTP id x10mr19140391pfq.114.1570835257317; Fri, 11 Oct 2019 16:07:37 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:36 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 09/14] software node: simplify property_entry_read_string_array() Date: Fri, 11 Oct 2019 16:07:16 -0700 Message-Id: <20191011230721.206646-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org There is no need to treat string arrays and single strings separately, we can go exclusively by the element length in relation to data type size. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index b11cc4dbff08..8826c9040c80 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -173,28 +173,21 @@ static int property_entry_read_string_array(const struct property_entry *props, const char *propname, const char **strings, size_t nval) { - const struct property_entry *prop; const void *pointer; - size_t array_len, length; + size_t length; + int array_len; /* Find out the array length. */ - prop = property_entry_get(props, propname); - if (!prop) - return -EINVAL; - - if (prop->is_array) - /* Find the length of an array. */ - array_len = property_entry_count_elems_of_size(props, propname, - sizeof(const char *)); - else - /* The array length for a non-array string property is 1. */ - array_len = 1; + array_len = property_entry_count_elems_of_size(props, propname, + sizeof(const char *)); + if (array_len < 0) + return array_len; /* Return how many there are if strings is NULL. */ if (!strings) return array_len; - array_len = min(nval, array_len); + array_len = min_t(size_t, nval, array_len); length = array_len * sizeof(*strings); pointer = property_entry_find(props, propname, length); From patchwork Fri Oct 11 23:07:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D0A01668 for ; Fri, 11 Oct 2019 23:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D6A2218AC for ; Fri, 11 Oct 2019 23:08:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kcKWitMK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728435AbfJKXIF (ORCPT ); Fri, 11 Oct 2019 19:08:05 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42900 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728080AbfJKXHj (ORCPT ); Fri, 11 Oct 2019 19:07:39 -0400 Received: by mail-pl1-f193.google.com with SMTP id e5so5107633pls.9; Fri, 11 Oct 2019 16:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VGAj9DcBs/80t0ryWN2g8AdvdOVG4qMHTqh7+k7I0Nc=; b=kcKWitMKklpsR5GYUZZJLuxueL0+AqvaRJGItrcqTG28pm3SZ+VUFlrmpfC5wy/sOm MwhiBZuGBxU66uzlaa/JjOJZmyAglVA4QnflG2dOABWMLn14rHmK7Sxi04NAwhAz/DNb TquinmOR94OnKAk/9oQDS5GslOMQRrrHduJr1r4OqdH5VIbVTTtXJotlL0VrNI2WQThy hBVblj0p2LQvDTXPktrXBSmCBVEoCshGhmj+JwJ+zgqYmujE99qx0RaBATuJq1Mkh9+8 prGHctDMy3pbvfeRppCidSyZmI7PwDxRwwo85VRt/iKqRsNpPQQ/7gRseFfZH9Mzpg5n pJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VGAj9DcBs/80t0ryWN2g8AdvdOVG4qMHTqh7+k7I0Nc=; b=aIaQAIi6wA5NnF2NyRR5EumB8YWAb4N2Ugako2LlkQa/mByC25/YdGCi03h+Je3gdv Ys+mlMO/McUuxc9URGAA0826Q7Ndf3F+h/cPiBpFVVFDZje13XW2+QmS5Ii+jEh3vWV3 v7wFEsyTrHA8HujwpMkAfvD1ql9i3JmOJDmlxpO2QI1Keo9nBbjivSYi6Q2yFYwi9fv1 RE1dUKKP3/Xb8vj0hmB6ErUWm43ZeNgp2xYAFH0rblSfnP82+owxpvocVoRN96EP9XuI 9USrkK/lXT1Q6Ggzu1E3ScxngIp2ZmncIQOPIdcwz/A3cvjbfeZyp3x2TXPEatZiisDF 8lZw== X-Gm-Message-State: APjAAAWG9TD0Y3PgmteLifVvMIz9Dt+ElckXpDO2pzWgLn6MQcX+JBKB bNeZcVSq8q6B3griurgoW7Q= X-Google-Smtp-Source: APXvYqwIKN74iRAFyhP89X4np83xFqjTvkIRJA+7KVwZOvEJkiwZtjkJU+1aWFpO5DLnu2VhiJ+icw== X-Received: by 2002:a17:902:8487:: with SMTP id c7mr17386776plo.20.1570835258560; Fri, 11 Oct 2019 16:07:38 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:37 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 10/14] software node: rename is_array to is_inline Date: Fri, 11 Oct 2019 16:07:17 -0700 Message-Id: <20191011230721.206646-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org We do not need a special flag to know if we are dealing with an array, as we can get that data from ratio between element length and the data size, however we do need a flag to know whether the data is stored directly inside property_entry or separately. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 9 +++++---- include/linux/property.h | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 8826c9040c80..ae4b24ee2a54 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -108,7 +108,7 @@ static const void *property_get_pointer(const struct property_entry *prop) if (!prop->length) return NULL; - if (prop->is_array) + if (!prop->is_inline) return prop->pointer; return &prop->value; @@ -205,7 +205,7 @@ static void property_entry_free_data(const struct property_entry *p) const char * const *src_str; size_t i, nval; - if (p->is_array) { + if (!p->is_inline) { if (p->type == DEV_PROP_STRING && p->pointer) { src_str = p->pointer; nval = p->length / sizeof(const char *); @@ -250,7 +250,7 @@ static int property_entry_copy_data(struct property_entry *dst, const void *pointer = property_get_pointer(src); const void *new; - if (src->is_array) { + if (!src->is_inline) { if (!src->length) return -ENODATA; @@ -264,15 +264,16 @@ static int property_entry_copy_data(struct property_entry *dst, return -ENOMEM; } - dst->is_array = true; dst->pointer = new; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) return -ENOMEM; + dst->is_inline = true; dst->value.str = new; } else { + dst->is_inline = true; dst->value = src->value; } diff --git a/include/linux/property.h b/include/linux/property.h index 238e1507925f..ac7823d58cfe 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -222,15 +222,17 @@ static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, * struct property_entry - "Built-in" device property representation. * @name: Name of the property. * @length: Length of data making up the value. - * @is_array: True when the property is an array. + * @is_inline: True when the property value is stored directly in + * &struct property_entry instance. * @type: Type of the data in unions. - * @pointer: Pointer to the property (an array of items of the given type). - * @value: Value of the property (when it is a single item of the given type). + * @pointer: Pointer to the property when it is stored separately from + * the &struct property_entry instance. + * @value: Value of the property when it is stored inline. */ struct property_entry { const char *name; size_t length; - bool is_array; + bool is_inline; enum dev_prop_type type; union { const void *pointer; @@ -257,7 +259,6 @@ struct property_entry { (struct property_entry) { \ .name = _name_, \ .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ - .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } @@ -288,6 +289,7 @@ struct property_entry { (struct property_entry) { \ .name = _name_, \ .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .is_inline = true, \ .type = DEV_PROP_##_Type_, \ { .value = { ._elem_ = _val_ } }, \ } From patchwork Fri Oct 11 23:07:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F27D717EE for ; Fri, 11 Oct 2019 23:08:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3CD02190F for ; Fri, 11 Oct 2019 23:08:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VrZ9QQbX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbfJKXHl (ORCPT ); Fri, 11 Oct 2019 19:07:41 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43363 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbfJKXHk (ORCPT ); Fri, 11 Oct 2019 19:07:40 -0400 Received: by mail-pl1-f193.google.com with SMTP id f21so5109900plj.10; Fri, 11 Oct 2019 16:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ny/ZNnxtQMyA+tF6f8WXbljYGPtP5sRnGWPW09z1Kxk=; b=VrZ9QQbXijQ3IOaDhrMxVR+ny2PMH4U0Aj8j9LitPUDlhC7BK0A9izSrCZnhiywLXk cJQvUhCuV5/m9VRelwK5FL8rjHH35ITpynZ2wMyK3les3DNOHyZdBEMduOw3hPN5wQgv VBrwzw3Od1P0pkkd6syrnS+PL2m1nFHD3Ez+scUhU2YNFgihJ/XmZDMJjzVssDobPgKr BGkaNCu/HowSlY0gGuNTVDPe1b/MdvoRqeY1JphQCiFWZVDevi4B3k54Lin2hxrD+lao FTxue0ePTPpH1mBlXtgCYtZBZiAw9kEl1rcMTbBLyePQqrWUBu2hht8mCK3InIQTPcA1 buBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ny/ZNnxtQMyA+tF6f8WXbljYGPtP5sRnGWPW09z1Kxk=; b=kDskm6y1ooMBBVBnGXIXXLMmOsuiolVc1BUvAFeszZl4iCoXvLpDbUTwILoAYIBRdD OM+Vf7ACj3x3jwsfiSbQXN1BqURLaPPYXjzrJ1QbSZmKd3SHFKD79K4rhNhOhd1l+mQI IbHcb+wXobXKlP/NO5eJH0olVIgDzi/NnYN0I+wOQyJA/U5exg53IY560kAHdW/R8CRO qkF2sN4oRPDEr5OfNpVA3XSiKz/NoLiHWbCauqWabnhVysNS+V3QJP8STS3zTG37vKOL fD0CxNA+VYyDPlaBNJHxqtpWI3Chg1NqhNEWSL8GTWD3EW8LMuCrcKVvc3Why3lrwN9L OvEQ== X-Gm-Message-State: APjAAAWSCToipr7mzU2J/Xbgk6voKK5hEMVwxhsoQZoYkJEuzA6vRH0a I+Q4OCi5IULXGfiIpdCg+Mc= X-Google-Smtp-Source: APXvYqzqtNRx6MTlbCZQQrmM3yLChsapiejXSFjXZOQGqYztMT476aNy6Q8zjCNHBA3i/Z2puYW+CQ== X-Received: by 2002:a17:902:9a06:: with SMTP id v6mr17417331plp.221.1570835259476; Fri, 11 Oct 2019 16:07:39 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:38 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 11/14] software node: move small properties inline when copying Date: Fri, 11 Oct 2019 16:07:18 -0700 Message-Id: <20191011230721.206646-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org When copying/duplicating set of properties, move smaller properties that were stored separately directly inside property entry structures. We can move: - up to 8 bytes from U8 arrays - up to 4 words - up to 2 double words - one U64 value - one or 2 strings. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index ae4b24ee2a54..546fc1b20095 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -277,6 +277,16 @@ static int property_entry_copy_data(struct property_entry *dst, dst->value = src->value; } + if (!dst->is_inline && dst->length <= sizeof(dst->value)) { + /* We have an opportunity to move the data inline */ + const void *tmp = dst->pointer; + + memcpy(&dst->value, tmp, dst->length); + dst->is_inline = true; + + kfree(tmp); + } + dst->length = src->length; dst->type = src->type; dst->name = kstrdup(src->name, GFP_KERNEL); From patchwork Fri Oct 11 23:07:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63FDB17D4 for ; Fri, 11 Oct 2019 23:07:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32D372190F for ; Fri, 11 Oct 2019 23:07:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OPtUyRe+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728191AbfJKXHo (ORCPT ); Fri, 11 Oct 2019 19:07:44 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45238 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728149AbfJKXHm (ORCPT ); Fri, 11 Oct 2019 19:07:42 -0400 Received: by mail-pf1-f196.google.com with SMTP id y72so6904386pfb.12; Fri, 11 Oct 2019 16:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mdKvjVQxyQUGKjLxy6nYZW0IwWeNpJokH5PyibB4u1c=; b=OPtUyRe+dXZHnDCkoCQ53Xh5Kwzg3d+4fpn4OKFhUf+PTolZzZ16ZcW5rK+XRD5aKf t7CPUsv109YN27NI6uv/Qux5yUtviKCYJKjQIgakNb3CDZqnqwMwx8lwrotF+cmz6Yds sjSI2qBYGBlkKxRCEVufZNFb1GPUSKJ7KmojQhuIT7/RTV1+aBCn6JZuv4MZjaw2VnAv AyCepBTW256kpMlKnFnu5B5k+PpZObZ41Q0+X4fuSb4nNZGl7ZyDPx05wdka/RRbc0Pt TzZ5y8v5m/ToAHJU/IYpAGuJbs8yTio/Zin/1ObiOChkqEc/RGpTVWU+mqGRKGwoTrzc jmvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mdKvjVQxyQUGKjLxy6nYZW0IwWeNpJokH5PyibB4u1c=; b=N1AakoeFjURVyQ4wRAZ4bX8sIsv46UTrVls5lb1dX96NFIRpkwqvEDk/auo5VVQPZu 6ZLhjWmYKxYurkXRmZyONYdTnIYbr7IxpPGd6Id5iDJJx0vpwlOy9OyMEHTj6JdBq5KZ Ca5yA7Bmyylo51ZrTlwA7Y/OonwPp1kCrXJQ9z2FBQukyIkqa4ojb52icwnKqXe1frIk zICYSi9gyYKZS1K+s6749kJREZLkJxOtaaC1g9NDtXv7UBq8DPN08j9/5a5/bSkoXBwB FzA2XdrhfKHV/B1mUHZxPvS0Ir8ieILG+D62+cBWAvJDziGysU3Egej72mSG4FgSK6eF w0Eg== X-Gm-Message-State: APjAAAVKvSU3BoOQj6cL58CXgvvJWttcQz0EFJccykrY6Vg1naNs9BA+ 9ZqC25Fvqy+1SI7ronN07CU= X-Google-Smtp-Source: APXvYqwXma+eNS+IwYOpARoOnoKmwOSVt1jdp1945WmdIQwzmtdRaLII18Uh2aR5pmNn4OEzwHRozQ== X-Received: by 2002:a17:90a:9ae:: with SMTP id 43mr20400861pjo.65.1570835261024; Fri, 11 Oct 2019 16:07:41 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:39 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 12/14] software node: implement reference properties Date: Fri, 11 Oct 2019 16:07:19 -0700 Message-Id: <20191011230721.206646-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org It is possible to store references to software nodes in the same fashion as other static properties, so that users do not need to define separate structures: static const struct software_node gpio_bank_b_node = { .name = "B", }; static const struct property_entry simone_key_enter_props[] = { PROPERTY_ENTRY_U32("linux,code", KEY_ENTER), PROPERTY_ENTRY_STRING("label", "enter"), PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW), { } }; Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 48 +++++++++++++++++++++++++++------ include/linux/property.h | 57 +++++++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 546fc1b20095..a5b592a4e956 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -265,6 +265,12 @@ static int property_entry_copy_data(struct property_entry *dst, } dst->pointer = new; + } else if (src->type == DEV_PROP_REF) { + /* + * Reference properties are never stored inline as + * they are too big. + */ + return -EINVAL; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) @@ -460,21 +466,47 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, { struct swnode *swnode = to_swnode(fwnode); const struct software_node_reference *ref; + const struct software_node_ref_args *ref_array; + const struct software_node_ref_args *ref_args; const struct property_entry *prop; struct fwnode_handle *refnode; int i; - if (!swnode || !swnode->node->references) + if (!swnode) return -ENOENT; - for (ref = swnode->node->references; ref->name; ref++) - if (!strcmp(ref->name, propname)) - break; + prop = property_entry_get(swnode->node->properties, propname); + if (prop) { + if (prop->type != DEV_PROP_REF) + return -EINVAL; - if (!ref->name || index > (ref->nrefs - 1)) - return -ENOENT; + /* + * We expect that references are never stored inline, even + * single ones, as they are too big. + */ + if (prop->is_inline) + return -EINVAL; + + if (index * sizeof(*ref_args) >= prop->length) + return -ENOENT; + + ref_array = prop->pointer; + ref_args = &ref_array[index]; + } else { + if (!swnode->node->references) + return -ENOENT; + + for (ref = swnode->node->references; ref->name; ref++) + if (!strcmp(ref->name, propname)) + break; + + if (!ref->name || index > (ref->nrefs - 1)) + return -ENOENT; + + ref_args = &ref->refs[index]; + } - refnode = software_node_fwnode(ref->refs[index].node); + refnode = software_node_fwnode(ref_args->node); if (!refnode) return -ENOENT; @@ -493,7 +525,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs; for (i = 0; i < nargs; i++) - args->args[i] = ref->refs[index].args[i]; + args->args[i] = ref_args->args[i]; return 0; } diff --git a/include/linux/property.h b/include/linux/property.h index ac7823d58cfe..08d3e9d126ef 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -22,6 +22,7 @@ enum dev_prop_type { DEV_PROP_U32, DEV_PROP_U64, DEV_PROP_STRING, + DEV_PROP_REF, }; enum dev_dma_attr { @@ -218,6 +219,20 @@ static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); } +struct software_node; + +/** + * struct software_node_ref_args - Reference property with additional arguments + * @node: Reference to a software node + * @nargs: Number of elements in @args array + * @args: Integer arguments + */ +struct software_node_ref_args { + const struct software_node *node; + unsigned int nargs; + u64 args[NR_FWNODE_REFERENCE_ARGS]; +}; + /** * struct property_entry - "Built-in" device property representation. * @name: Name of the property. @@ -255,14 +270,20 @@ struct property_entry { #define __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_) \ sizeof(((struct property_entry *)NULL)->value._elem_) -#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ +#define __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, _elsize_, _Type_, \ + _val_, _len_) \ (struct property_entry) { \ .name = _name_, \ - .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .length = (_len_) * (_elsize_), \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ + __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ + __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + _Type_, _val_, _len_) + #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ @@ -273,6 +294,10 @@ struct property_entry { __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) +#define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_) \ + __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ + sizeof(struct software_node_ref_args), \ + REF, _val_, _len_) #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) @@ -284,6 +309,8 @@ struct property_entry { PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ @@ -310,6 +337,18 @@ struct property_entry { .name = _name_, \ } +#define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \ +(struct property_entry) { \ + .name = _name_, \ + .length = sizeof(struct software_node_ref_args), \ + .type = DEV_PROP_REF, \ + { .pointer = &(const struct software_node_ref_args) { \ + .node = _ref_, \ + .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \ + .args = { __VA_ARGS__ }, \ + } }, \ +} + struct property_entry * property_entries_dup(const struct property_entry *properties); @@ -373,20 +412,6 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -struct software_node; - -/** - * struct software_node_ref_args - Reference with additional arguments - * @node: Reference to a software node - * @nargs: Number of elements in @args array - * @args: Integer arguments - */ -struct software_node_ref_args { - const struct software_node *node; - unsigned int nargs; - u64 args[NR_FWNODE_REFERENCE_ARGS]; -}; - /** * struct software_node_reference - Named software node reference property * @name: Name of the property From patchwork Fri Oct 11 23:07:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB0CD17EE for ; Fri, 11 Oct 2019 23:07:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2F0D214E0 for ; Fri, 11 Oct 2019 23:07:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gx0o2RGr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728203AbfJKXHp (ORCPT ); Fri, 11 Oct 2019 19:07:45 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46297 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbfJKXHn (ORCPT ); Fri, 11 Oct 2019 19:07:43 -0400 Received: by mail-pg1-f195.google.com with SMTP id b8so6584584pgm.13; Fri, 11 Oct 2019 16:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VI0wKvjDgbdTNJZtcyLAENSiJDcwdTO7f/A/TIGCTLM=; b=Gx0o2RGriLBV8cbs0OnUvP/4pWyHa7+VtAhLUq7LV9fNGmUNU47zoMGbtqlU/nQJDK Xw6qQQzMp3FqCSawPzx5nRIyoYdu44bKlWyqR4a1+RrzmUA62YNksZH8MH4CyEpTlpUJ PGOZVx/gCgIt3QIGgvwmC++OAP+6z1YNhZ68x/26v9QuTF7HpfHBr0FQdGGErbyoxUKa z9fMxuSEVvKSluIaID0GFMn7K2wXyMgAtWoBa6f/D6xGZ12CUrrrPuzBKST1nLgqOOgT YLNqrcRRv02IfbPAcvohGAIwGI7ZHPKALPj8wt6BgpKaFbv7+Q4FW+FyC7lUcYe5iLlY qE0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VI0wKvjDgbdTNJZtcyLAENSiJDcwdTO7f/A/TIGCTLM=; b=CiJ253G2uSl9FJyQ0NAe9GTNwYapjJEfQ8lv3XxPRxInN7t/k0Ylk8UA4G9F1BXpv/ CZGV/pD1bE4P0yhJ1u5+hVsBJoNqcJSNeOReSU1yLOy34PRGx6ifS4tLeRyHBJ6VH/Bb Krb5AKzwDF1g3TkcKT2MlvzYdk7sqWELDcffq5OdYiS7vFfhjXLG1/BjBbbAmYhp3cK/ XKpmGi9XrGQXWC0gNJ5K3X58Me4PL/VnVpmQ0m0X/9sXTesOLz7jQ6TOQ6W8SZ5ELHn3 eRGukLskkPvMQ62xEIZGes23Xt36Rfqlz9ke+Hb2DEVVqOSOVvZwEai8DyWXZZeV/aAW O+Sg== X-Gm-Message-State: APjAAAX9f8rXBUHXKyGmjjayQkr3KBILafBaR5t7sjjBtkIda6cAUiQi FpelI7CTe7Hn6txiE8vmMDCiS+XS X-Google-Smtp-Source: APXvYqwaGBd09iNquwz7S4iILp082tE5rlgHTaxUG9S9enl0ztOdQUqxuTgXVBrlBChYgDOIhIEASg== X-Received: by 2002:a17:90a:948a:: with SMTP id s10mr20352805pjo.47.1570835261916; Fri, 11 Oct 2019 16:07:41 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:41 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 13/14] platform/x86: intel_cht_int33fe: use inline reference properties Date: Fri, 11 Oct 2019 16:07:20 -0700 Message-Id: <20191011230721.206646-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Now that static device properties allow defining reference properties together with all other types of properties, instead of managing them separately, let's adjust the driver. Signed-off-by: Dmitry Torokhov Acked-by: Andy Shevchenko --- drivers/platform/x86/intel_cht_int33fe.c | 81 ++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/platform/x86/intel_cht_int33fe.c b/drivers/platform/x86/intel_cht_int33fe.c index 1d5d877b9582..4177c5424931 100644 --- a/drivers/platform/x86/intel_cht_int33fe.c +++ b/drivers/platform/x86/intel_cht_int33fe.c @@ -46,30 +46,6 @@ struct cht_int33fe_data { struct fwnode_handle *dp; }; -static const struct software_node nodes[]; - -static const struct software_node_ref_args pi3usb30532_ref = { - &nodes[INT33FE_NODE_PI3USB30532] -}; - -static const struct software_node_ref_args dp_ref = { - &nodes[INT33FE_NODE_DISPLAYPORT] -}; - -static struct software_node_ref_args mux_ref; - -static const struct software_node_reference usb_connector_refs[] = { - { "orientation-switch", 1, &pi3usb30532_ref}, - { "mode-switch", 1, &pi3usb30532_ref}, - { "displayport", 1, &dp_ref}, - { } -}; - -static const struct software_node_reference fusb302_refs[] = { - { "usb-role-switch", 1, &mux_ref}, - { } -}; - /* * Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates * the max17047 both through the INT33FE ACPI device (it is right there @@ -105,8 +81,18 @@ static const struct property_entry max17047_props[] = { { } }; +/* + * We are not using inline property here because those are constant, + * and we need to adjust this one at runtime to point to real + * software node. + */ +static struct software_node_ref_args fusb302_mux_refs[] = { + { .node = NULL }, +}; + static const struct property_entry fusb302_props[] = { PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"), + PROPERTY_ENTRY_REF_ARRAY("usb-role-switch", fusb302_mux_refs), { } }; @@ -122,6 +108,8 @@ static const u32 snk_pdo[] = { PDO_VAR(5000, 12000, 3000), }; +static const struct software_node nodes[]; + static const struct property_entry usb_connector_props[] = { PROPERTY_ENTRY_STRING("data-role", "dual"), PROPERTY_ENTRY_STRING("power-role", "dual"), @@ -129,15 +117,21 @@ static const struct property_entry usb_connector_props[] = { PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo), PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo), PROPERTY_ENTRY_U32("op-sink-microwatt", 2500000), + PROPERTY_ENTRY_REF("orientation-switch", + &nodes[INT33FE_NODE_PI3USB30532]), + PROPERTY_ENTRY_REF("mode-switch", + &nodes[INT33FE_NODE_PI3USB30532]), + PROPERTY_ENTRY_REF("displayport", + &nodes[INT33FE_NODE_DISPLAYPORT]), { } }; static const struct software_node nodes[] = { - { "fusb302", NULL, fusb302_props, fusb302_refs }, + { "fusb302", NULL, fusb302_props }, { "max17047", NULL, max17047_props }, { "pi3usb30532" }, { "displayport" }, - { "connector", &nodes[0], usb_connector_props, usb_connector_refs }, + { "connector", &nodes[0], usb_connector_props }, { } }; @@ -173,9 +167,10 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) { software_node_unregister_nodes(nodes); - if (mux_ref.node) { - fwnode_handle_put(software_node_fwnode(mux_ref.node)); - mux_ref.node = NULL; + if (fusb302_mux_refs[0].node) { + fwnode_handle_put( + software_node_fwnode(fusb302_mux_refs[0].node)); + fusb302_mux_refs[0].node = NULL; } if (data->dp) { @@ -187,25 +182,31 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) static int cht_int33fe_add_nodes(struct cht_int33fe_data *data) { + const struct software_node *mux_ref_node; int ret; - ret = software_node_register_nodes(nodes); - if (ret) - return ret; - - /* The devices that are not created in this driver need extra steps. */ - /* * There is no ACPI device node for the USB role mux, so we need to wait * until the mux driver has created software node for the mux device. * It means we depend on the mux driver. This function will return * -EPROBE_DEFER until the mux device is registered. */ - mux_ref.node = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); - if (!mux_ref.node) { - ret = -EPROBE_DEFER; - goto err_remove_nodes; - } + mux_ref_node = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); + if (!mux_ref_node) + return -EPROBE_DEFER; + + /* + * Update node used in "usb-role-switch" property. Note that we + * rely on software_node_register_nodes() to use the original + * instance of properties instead of copying them. + */ + fusb302_mux_refs[0].node = mux_ref_node; + + ret = software_node_register_nodes(nodes); + if (ret) + return ret; + + /* The devices that are not created in this driver need extra steps. */ /* * The DP connector does have ACPI device node. In this case we can just From patchwork Fri Oct 11 23:07:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11186453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 860101668 for ; Fri, 11 Oct 2019 23:07:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DB31214E0 for ; Fri, 11 Oct 2019 23:07:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pC0LY6U/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728239AbfJKXHs (ORCPT ); Fri, 11 Oct 2019 19:07:48 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38977 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728209AbfJKXHq (ORCPT ); Fri, 11 Oct 2019 19:07:46 -0400 Received: by mail-pg1-f196.google.com with SMTP id e1so6611813pgj.6; Fri, 11 Oct 2019 16:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S0//uf0M37JZw3nISBvezCORU54B4ZZcLP9zD7cFu34=; b=pC0LY6U/44gpmU6UUdSKZ9hNbdX8XXx2aDAnQiDTvUbEHGMtEWH+zjvk/M1Fyyy9Uu xmwZW4Z9rhpzRoU3FjmHFis9MTRtqwiih6//B2XJKnJaQrnfwvbt/XhyfoB8MjpPCGO6 im7v6KeOh5samYuQW4qSthXnynnvTej/HiybhKjTvY6/lZnqWnzk9VMYo1NuH9vfhofK AGQF0K6MP0OnOVKLhMcZT06M1JO80M7jte1K0A06hoKVy1OAZrWEEi5Soh/A2Iq7eLoP sHx1C5KCtDWf9WHyyKkV/VH2X/+saF+w42bAh//w5CI5ufKLMYlz7fkTDIKiycjQE2z3 Ebgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S0//uf0M37JZw3nISBvezCORU54B4ZZcLP9zD7cFu34=; b=iH7cBjV3Ea2yvLMwKiTYlwuGj7ZjmFr7RVfB20ZMl0gyPdIriEYmRibzb9SQ8rfYj1 k0Fl+Qrr+BwGcgRAm4aSYfYoLL1psAoau3Q+p/hGJZVdLJi7DcXBU9+n/xnhh0CvpH7X efSpAXlDEsgSkBih+cZQloI46uPO76RCK6ykUba7eX3ZjyXoJ9PXrbXrvHTan7bIJByU w7m5jYh6GRMlWrr0s1gxpjPT+bQzGK86EkUuo8O3fNvi2eRTmd8EmJfU2iKebV26MGv9 PwsnDObta2r00F3SEIgKcNeflFKjAw7qUp1wXMQpTBsVS5kty7PMadY2NPHt9zOnjCyx 3zxQ== X-Gm-Message-State: APjAAAUpF6acDDB5v96KDdmAoWsUl17N3ctivAB9E2DrkJglD9MIKQOo 3RyQLUFvDOIDIFvOps8+UvZxOvKP X-Google-Smtp-Source: APXvYqz/TR8uDeeYkhJAxOu1rC6UATHW4Lrnd0hhlLSi5qIrvJirjHPF8WSDaOTCRaZDRVJ+X/YTjw== X-Received: by 2002:a17:90a:19c1:: with SMTP id 1mr20378906pjj.52.1570835264154; Fri, 11 Oct 2019 16:07:44 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w2sm11529251pfn.57.2019.10.11.16.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 16:07:42 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Mika Westerberg , Linus Walleij , Ard Biesheuvel , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v5 14/14] software node: remove separate handling of references Date: Fri, 11 Oct 2019 16:07:21 -0700 Message-Id: <20191011230721.206646-15-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog In-Reply-To: <20191011230721.206646-1-dmitry.torokhov@gmail.com> References: <20191011230721.206646-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Now that all users of references have moved to reference properties, we can remove separate handling of references. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 46 +++++++++++++++------------------------- include/linux/property.h | 14 ------------ 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index a5b592a4e956..4cb62cd105db 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -465,9 +465,8 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, struct fwnode_reference_args *args) { struct swnode *swnode = to_swnode(fwnode); - const struct software_node_reference *ref; const struct software_node_ref_args *ref_array; - const struct software_node_ref_args *ref_args; + const struct software_node_ref_args *ref; const struct property_entry *prop; struct fwnode_handle *refnode; int i; @@ -476,37 +475,26 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, return -ENOENT; prop = property_entry_get(swnode->node->properties, propname); - if (prop) { - if (prop->type != DEV_PROP_REF) - return -EINVAL; - - /* - * We expect that references are never stored inline, even - * single ones, as they are too big. - */ - if (prop->is_inline) - return -EINVAL; - - if (index * sizeof(*ref_args) >= prop->length) - return -ENOENT; + if (!prop) + return -ENOENT; - ref_array = prop->pointer; - ref_args = &ref_array[index]; - } else { - if (!swnode->node->references) - return -ENOENT; + if (prop->type != DEV_PROP_REF) + return -EINVAL; - for (ref = swnode->node->references; ref->name; ref++) - if (!strcmp(ref->name, propname)) - break; + /* + * We expect that references are never stored inline, even + * single ones, as they are too big. + */ + if (prop->is_inline) + return -EINVAL; - if (!ref->name || index > (ref->nrefs - 1)) - return -ENOENT; + if (index * sizeof(*ref) >= prop->length) + return -ENOENT; - ref_args = &ref->refs[index]; - } + ref_array = prop->pointer; + ref = &ref_array[index]; - refnode = software_node_fwnode(ref_args->node); + refnode = software_node_fwnode(ref->node); if (!refnode) return -ENOENT; @@ -525,7 +513,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs; for (i = 0; i < nargs; i++) - args->args[i] = ref_args->args[i]; + args->args[i] = ref->args[i]; return 0; } diff --git a/include/linux/property.h b/include/linux/property.h index 08d3e9d126ef..fa5a2ddc0c7b 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -412,30 +412,16 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -/** - * struct software_node_reference - Named software node reference property - * @name: Name of the property - * @nrefs: Number of elements in @refs array - * @refs: Array of references with optional arguments - */ -struct software_node_reference { - const char *name; - unsigned int nrefs; - const struct software_node_ref_args *refs; -}; - /** * struct software_node - Software node description * @name: Name of the software node * @parent: Parent of the software node * @properties: Array of device properties - * @references: Array of software node reference properties */ struct software_node { const char *name; const struct software_node *parent; const struct property_entry *properties; - const struct software_node_reference *references; }; bool is_software_node(const struct fwnode_handle *fwnode);