From patchwork Wed Oct 23 20:02: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: 11207443 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 76806139A for ; Wed, 23 Oct 2019 20:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54E6121A4A for ; Wed, 23 Oct 2019 20:02:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kd4I7/+T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405131AbfJWUCl (ORCPT ); Wed, 23 Oct 2019 16:02:41 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37197 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfJWUCl (ORCPT ); Wed, 23 Oct 2019 16:02:41 -0400 Received: by mail-pf1-f195.google.com with SMTP id y5so13588331pfo.4; Wed, 23 Oct 2019 13:02: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=o+uaR80mWxyEyufNFdwT5uU4rIjXURMixrRxXLGkFjQ=; b=Kd4I7/+T96ZcdbGqu9kwHt2mNR2SK6++Jywk+f9ipxuZ5XE+r4S+MKHXYekPYzHUny lQ4IZ+9lhaTeusxu4XAkm3pJD3DDA4MVdy8AzdPTb8+hX3izl/XsYOwYfmvhjSCIxubm wcjmU1pMvpLlaJ1M/3LBMzWksN81+rrugzLyRvNSSZ8aXjoltWGJNPX+f6Kewmr6yBHF tMjir14lsijueio2Fm/Y4cjZJt0J0T8ZJoO4SNpqX4nGN6V4jl0qFh20HZyxaR+uHmzB IX8b1VKJyXCrpwxgvwa9D7AqSgi3mkshmrsgHjpM9eTCp9wYYZanWjNIeL1etMhuZxWc 8qnw== 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=o+uaR80mWxyEyufNFdwT5uU4rIjXURMixrRxXLGkFjQ=; b=ZAMTbWuktKOfwD91fBW8cjVEfw0DPbXqY5CYbpcdHZf9p8QjSwgmL0Y8Sy+NMyL4XV qNZbLO/eDXkVag18FLM4CTMS3c00vvDClhJoaChfvBXn6oGJl8dBTZiKHkVa3odsK77z E8g6skHQXkjFoxZ6ngSRzFJHPicjTVCf+LjTM0BeAZc6FZ/lizEOFMLyqZkn2SjLNQpb f7K/Hmn6kJtXVDewKyOrKhfSdbU64xz8xJ5lSu8XDaGzu6k5AeLzJdWemfO/xvmgpGUD w8ZolznMv2itKMl7cjjz7YwuCRpoaLH69nsWsiQTPCmEI5fYlbhrouWOOuFGYoDnMcxy fK8Q== X-Gm-Message-State: APjAAAXbD9CQX5q8fuEVeZ1Kl0j3UmXGOv/jAOcFNGpFCdqs5t5DvKYo K/3n7MQxXz0NeAogcYkq9TE= X-Google-Smtp-Source: APXvYqzk2kFSSSIPZCcAa9BCC65JFT24sxV3J3C8eiGVaYoIhDM22tDEcFoBcHCaftifD9Z4ORTCxg== X-Received: by 2002:a17:90a:e2ce:: with SMTP id fr14mr2222496pjb.59.1571860960237; Wed, 23 Oct 2019 13:02:40 -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 6sm10593598pfy.43.2019.10.23.13.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02: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 v6 01/15] software node: remove DEV_PROP_MAX Date: Wed, 23 Oct 2019 13:02:19 -0700 Message-Id: <20191023200233.86616-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 054661109661..0a075fbde57e 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 Wed Oct 23 20:02: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: 11207495 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 58D41112B for ; Wed, 23 Oct 2019 20:03:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2CF1C21D71 for ; Wed, 23 Oct 2019 20:03:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GqnXmdlc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405235AbfJWUCp (ORCPT ); Wed, 23 Oct 2019 16:02:45 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38351 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfJWUCp (ORCPT ); Wed, 23 Oct 2019 16:02:45 -0400 Received: by mail-pl1-f194.google.com with SMTP id w8so10618430plq.5; Wed, 23 Oct 2019 13:02:43 -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=gvRK+5ta158WSRKlg8UZ8EljQRMjRoa7C71YFmxtYTY=; b=GqnXmdlc839iWseVEk6Cne9M0s+dbcz+nMRzgB7ruYIhC8mjYNbk12mnznyGhO3B3j xUszYpy51kKteiKBIVUfnPNIa32ZTgwZvP07OhMulm9CPMLECyu7TgpTrxqAcmGeIorn kOLSsTOdZZiCspxvJUXTCgqBYAW77aBpAYLSqWfrlJGJHhbrJRj+0z1euShiSbFGT0CF nenR/qVX48TGmrd8O4bAOLsfhhja+kj2VvmlhnnVTr5ObVYsLOksQDUEOcRg91IDspdP +/h6HlkmJB6ulsWHUexjG6HBaQsKaoyJy7OvdZ1VR/AMah/hSwsvH0ALRD8m/opgSsO7 uCJw== 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=gvRK+5ta158WSRKlg8UZ8EljQRMjRoa7C71YFmxtYTY=; b=NxFl9QGqs11vEW5Kb+KLoXmpSWrDrhqlvCvfOtY+uhUjCkuJJknw1kgTMtVfaOBykL tWFSloflCxdq8IgaphbSW02arEoMWymzuX65fPv+EWfAAm4Ajvq2qKZ08QNEKidVcIKv +fwRdBQj/D+10+pJ4xQ03Xd7gbXpgORKHYM7ztd7eCPed1uyuAu+NLVN2icV2rK1Xx84 K28m6n4A1SPKVQccHuPx60nmXJW86ZJ7g1NCxpZXZuWJIZDDKLsOBM9ij9ozqhHNp8pT vXp9AS6xKaS2RFmMe4KMg617160YgfQk/9VNSnzPX1uYDLsDuV7IcV2oB29c8U52OozT 36hQ== X-Gm-Message-State: APjAAAWg6ReRk9sim5FDD1W++PGhxGUMgCSi8070z0p3FtydR91pIciu z0tKJG6Hqn2i9V+KbLtc66OtiELd X-Google-Smtp-Source: APXvYqyPR4okpEq8LkKZ051NG5ryaeethDnwUSSdGo1XCoLCVznCHtK+1/+evkQ4gyVgW/RWE3lZzQ== X-Received: by 2002:a17:902:8d89:: with SMTP id v9mr284051plo.247.1571860962401; Wed, 23 Oct 2019 13:02:42 -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 6sm10593598pfy.43.2019.10.23.13.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02: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 v6 02/15] software node: introduce PROPERTY_ENTRY_ARRAY_XXX_LEN() Date: Wed, 23 Oct 2019 13:02:20 -0700 Message-Id: <20191023200233.86616-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- 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 0a075fbde57e..fad2e83a207c 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -261,33 +261,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 Wed Oct 23 20:02: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: 11207497 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 5B361112B for ; Wed, 23 Oct 2019 20:03:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3844621929 for ; Wed, 23 Oct 2019 20:03:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bl1g34Mk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405195AbfJWUCp (ORCPT ); Wed, 23 Oct 2019 16:02:45 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40666 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405185AbfJWUCp (ORCPT ); Wed, 23 Oct 2019 16:02:45 -0400 Received: by mail-pg1-f194.google.com with SMTP id 15so7411414pgt.7; Wed, 23 Oct 2019 13:02: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=qtC7CH3uCwc1qnA7SQUM9vPjiJGHmllhEByKdOb4NKs=; b=Bl1g34Mkp5wfx+KC9+klwhpKZk1kBhcM5NRp3FEFF07RQNZcVc4o24x1U11z10h6M6 LCIeI2Dy1qVdyeYk7Ldx8r3o/qs/FDyIX3QfJUJZyD6lq6pPMhvkUrpaqPFqgaYiyrc3 6AIibK6lfZYm/yIMhlv+VDOye62lgOM16ixQJY6NjpXW1cRbUnAW2sfmJmSkBRg0iuQU 3TSJB9Avz/zvs2sutC7DOVkbaoMD3gD+J/KdR/CbqCL7putsPB1Epk4uelX31SWDQwYo 5ackelqsjcnw8GQO5oqsP47ZlhuqjTzYI4ozItX8zAvf0I5EN94RSc+j0ee8WUme0gEd 1FoQ== 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=qtC7CH3uCwc1qnA7SQUM9vPjiJGHmllhEByKdOb4NKs=; b=F4DSrxN/ZVYhh0GomiSfJkljFcfjhyAd2MJ4VjdSz5wFsO+EPZk0MVLQoLGpz47yZu r716THGct8pGd2bG0O8jfxMENyOWArPyhyOSWNy8IcgvTs4hA3mCRkEhy5/88srm/70A YL53po063wjZKE2+y/MHH9OwrP3M2sh5YxkYAHTS+YFVbGdtsu49PR4edo6FjA9Fy8OB vBbCFUrfSNTK5i/vM/5d7WD4iS+23Vbuayy4CakiWxL51mBIUbdIzOtyP8X3tGN307q5 aGxGFm9ZM9Un/y36WRTjORHbL+0tkMaNHpm9zLCa8BKfywdvmmGkQnu9CNd+cF8csQpL zwNw== X-Gm-Message-State: APjAAAUaFh0LFXzXCGx7wMLD890FbHTYbJ45BLFRKJ5PCcAgK0LxbGQT BuiULh16sqMIwbHlK+t8lic= X-Google-Smtp-Source: APXvYqxrtG+HMKhqIm6N7hCHG05q+xOQ8FHVy0CHWWfKPchAcaWeOKq4CAT1YBwjvkyfK5HeusGoGw== X-Received: by 2002:a63:6949:: with SMTP id e70mr11937570pgc.226.1571860963943; Wed, 23 Oct 2019 13:02:43 -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 6sm10593598pfy.43.2019.10.23.13.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02: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 v6 03/15] efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN Date: Wed, 23 Oct 2019 13:02:21 -0700 Message-Id: <20191023200233.86616-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- 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 Wed Oct 23 20:02:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207493 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 389AE1515 for ; Wed, 23 Oct 2019 20:03:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1685721929 for ; Wed, 23 Oct 2019 20:03:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kdaK28na" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405325AbfJWUCs (ORCPT ); Wed, 23 Oct 2019 16:02:48 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40668 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405250AbfJWUCq (ORCPT ); Wed, 23 Oct 2019 16:02:46 -0400 Received: by mail-pg1-f194.google.com with SMTP id 15so7411455pgt.7; Wed, 23 Oct 2019 13:02:45 -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=QQpe2VSd833fMVSnCEuCtaneErs8UtbkJfg8Hab68oA=; b=kdaK28naNBUwj6a4ZZ/2PHgGkOWbyACEdEqBSql9+Gd5j/3lB0KrC4tlenrticjPP3 ntktb+2yu2ei7VLvN0KaGGz1PlkSm8ipW4x2HUZDJK7TUGZ2TX8I8WSHH+X7eVhvbK9D Rx8HONM7PXFQ6DH0yFVAfQMZRvRABHyduJHbU9Y9kIfj/I+I/VM53SozVz9nICadbmcu GI5aoOoyjPSsgcoTrDgY1RamCx90Fl1xVoNezPlMpBdyCbsXUPGafVe300Gy8nM5Ens+ KOhyc0HduO0V+sv3tYcjAaNV/+sQ+8fptPhSNDLcIcBIgw4cNT0gHKyS+fMDoxERmDIN e21w== 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=QQpe2VSd833fMVSnCEuCtaneErs8UtbkJfg8Hab68oA=; b=eJQpffbNV1a59tzKhAQ2a1dHeAOKJcvUpaPEzOaImFcHUMsYQ/OsGskNpz5T7nZBUm q3RrsK39mmrqNg7QgB4OtG7WVGEmhqiF7RkX5uQf1kO6CUp7L8OOjimiqMZ4p2NtyfCp VOVaWNbGRFXoda7xjyrtKRTO+u70rZ1D7OJM1hU1jtGScYPcHGjBAPAkDzHVjyl1e1Yf E7LfQ7g10pY56E1I9wQ4LNimguJCNsSYTKClUsbkKIw9x8jN77FOyvPqhXTQVgd/iPJ8 0UTqiigkbgnhUU2eShn77N7dZJtjcH622KUsuVAHyXjmePMgsJsDn8qwqLgo4KTmlqdy wtqA== X-Gm-Message-State: APjAAAXWbrPocndWFtqgHSQjKHH4DwGGp3UufDwYb5ubBrEVEuMP1lsK ieDIjpqLYwuTorNcYMh3gIY= X-Google-Smtp-Source: APXvYqxyRgz+W/NS2FHRZwiG5KqfvAyLK6GpAsMwYR990mOz0HPTghKwR31MlMVcd7C+xpFzf4mq0A== X-Received: by 2002:a65:6781:: with SMTP id e1mr12243091pgr.173.1571860965210; Wed, 23 Oct 2019 13:02:45 -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 6sm10593598pfy.43.2019.10.23.13.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:44 -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 v6 04/15] software node: mark internal macros with double underscores Date: Wed, 23 Oct 2019 13:02:22 -0700 Message-Id: <20191023200233.86616-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 fad2e83a207c..d6019bacd848 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -261,7 +261,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_), \ @@ -271,13 +271,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) { \ @@ -299,7 +299,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_), \ @@ -308,13 +308,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 Wed Oct 23 20:02:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207491 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 538F01515 for ; Wed, 23 Oct 2019 20:03:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3177C21929 for ; Wed, 23 Oct 2019 20:03:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HWzChNfm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404790AbfJWUDj (ORCPT ); Wed, 23 Oct 2019 16:03:39 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38565 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfJWUCs (ORCPT ); Wed, 23 Oct 2019 16:02:48 -0400 Received: by mail-pg1-f194.google.com with SMTP id w3so12759935pgt.5; Wed, 23 Oct 2019 13:02:47 -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=v3H54pMajw9vQAImO1zQUK9pcXc+MkHfH1n0XYG6X74=; b=HWzChNfmQ2anc5V0nyw5UhLaS86AenhkOOnkjnHMCUOQ8ZgjQdz2KeoZC1SeuliTgc 9z3PO9ilE1TIlWVjviGlnCy/RywbMmphIDVwG4+sNS9lYCs4khxqD6ZnxN8xLzEVSgaJ CdbEaqCyhUFsyzDY/TnN9Hsih/DLPh06gm2qHb1Wmx/yjPoqZaX5PILpkbMAyDLVWKlA vdQEQKjlBju2ri2apFO36moIywuaxLp05/ny78ZU1cmGud0F1tDw1VeJ9Y7HKRjCEI6L JM+As0f9rhEqcpNWaW30LyYn5X3t9mwYizRAhz3bSewfIVrWImAujlTth0I5IXj7pDJa 7meg== 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=v3H54pMajw9vQAImO1zQUK9pcXc+MkHfH1n0XYG6X74=; b=gQt6yMqg/9Xc4QhA1Vb4pqYS4/C6PjLaLy8XvGw+VkeRRQAMR7ZpMe0qnOjYNTF3YB 3C2ddfFquKFvIsat/EWxhyLNvutO7YrK2xauTH95KRL5t5M48Zh1nycoedmVoL+vWVk2 gqJdZu7O7Zu2DGPzKIZ8D0w5Udw5frq8XSuE7IrV0YfwfK059xiL+Y1hnrGPixjLDMCH a9XLpEYO7LXVaiCfuXkS5J5+xEIBQo6bkWJsGvOg+n5txUM2N/Vj59j4hwP2oJPzRqed P9b02uYPn3zEY1a1frUZNINxsjyUGXSc4wWl2oMa7Zn5vDmFapy5XeM3pfBRi9puqQqS rKzw== X-Gm-Message-State: APjAAAXqYfnQCyO52a5LlRce8OJAAmHi9lU4oFyhdgOgQs1yQ1BSc/Kd ld3iigtcxjO3X1qWkYTJl6k= X-Google-Smtp-Source: APXvYqx2dQjzCEQV0a9JbYtyY0kDCslgGRmIpudMlu+R4NLpxGsBIq5EXVcukjcdBFhjDxCwVbX+Qg== X-Received: by 2002:a63:ce0d:: with SMTP id y13mr6007108pgf.430.1571860966900; Wed, 23 Oct 2019 13:02:46 -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 6sm10593598pfy.43.2019.10.23.13.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:45 -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 v6 05/15] software node: clean up property_copy_string_array() Date: Wed, 23 Oct 2019 13:02:23 -0700 Message-Id: <20191023200233.86616-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 12ca439bab30..f41692e0f63b 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 Wed Oct 23 20:02:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207447 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 EFB18112B for ; Wed, 23 Oct 2019 20:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C42CD21D7B for ; Wed, 23 Oct 2019 20:02:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P1AL0t95" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405360AbfJWUCu (ORCPT ); Wed, 23 Oct 2019 16:02:50 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43104 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405250AbfJWUCt (ORCPT ); Wed, 23 Oct 2019 16:02:49 -0400 Received: by mail-pf1-f193.google.com with SMTP id a2so13588323pfo.10; Wed, 23 Oct 2019 13:02:49 -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=E4mNM5mJotUAYNSU0vj/fSOZ8Nl4ZQb67KQvwfFGcWE=; b=P1AL0t955F72dVC4EwQ1KiaFVlEcyiWIVUZBww0avHwp33oIkg+6qPwSjxctlbGhBv yIWM+uJDOHOBD4Bm4CMAVAd5BQc0Ez4BxeIix3fz33Ft6J0JhVtNCMEP9/u0xvBlHT8z FHahhb6a53He4PfK07Xn+Wv108gvLJxwEIv2HNTWMloRnCjUlBBmPoz0kDQHbfVScKju 3xtHm4UDZczdvkAgqpR7A+qlBJLNRXUqFby+6x1zRXtgJt7F0yCSspO2ePt3ZVnnSNtT ot0y9/6gVOIVNjBwKjNqkwMU5g1F1QNJgsx4rvgRed4Yajvysy3DieMKkt19f8uVggU/ Um2w== 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=E4mNM5mJotUAYNSU0vj/fSOZ8Nl4ZQb67KQvwfFGcWE=; b=dXsQW7oSG34cdBa3WIxAopeJqUMZilOW5TH3m28PEBtjUfTSVhcG713tTic0aSOsAA 0lEqzN8oxwDPZCXr0Dqd5qwKOn+NEdTdJLqRa17BHqZ5Bt57/A1EQFfRkHrBBABOWEvY dzzhSoHX2ASX2CceF6sRPB6zEjscLRRCLjOOZRJ9ELRNfO8ZUZJdJQJiwh5okVUUy4vX Nl2rybskSQj7ZsKn2kLUMRRmq4uHYZLYnEm0PCQv+IcI5Ji29oiux1la3Qn++0mF9Y8+ f17G/G3Nml5GzmSjp/Pr4htv5s+xGRxPhbif/wRfGtL6BwO5+bQ7CDwmmLfFTS9ByhOf y+zw== X-Gm-Message-State: APjAAAX2pqoelkMMRicJq70tDXoiJT2G7RKCk32XA8OBNe42VKTwafjL FA7MfywzXorwwrox1b49XMY= X-Google-Smtp-Source: APXvYqyv+UPOoeAht2DDHkoFPH8pdqS9e6HXJKMnt/5rtCif10V7PSNTCWCKfxQg9Gy+RbuZFeUY9A== X-Received: by 2002:a63:330f:: with SMTP id z15mr11921768pgz.231.1571860968415; Wed, 23 Oct 2019 13:02:48 -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 6sm10593598pfy.43.2019.10.23.13.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:47 -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 v6 06/15] software node: get rid of property_set_pointer() Date: Wed, 23 Oct 2019 13:02:24 -0700 Message-Id: <20191023200233.86616-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 f41692e0f63b..fd667a73a201 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 d6019bacd848..12eff7cbb395 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -238,13 +238,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; @@ -267,7 +261,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_) \ @@ -285,7 +279,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 Wed Oct 23 20:02:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207449 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 EF06B139A for ; Wed, 23 Oct 2019 20:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C1EE321928 for ; Wed, 23 Oct 2019 20:02:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qjt/QIY1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405386AbfJWUCw (ORCPT ); Wed, 23 Oct 2019 16:02:52 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38930 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405370AbfJWUCw (ORCPT ); Wed, 23 Oct 2019 16:02:52 -0400 Received: by mail-pg1-f193.google.com with SMTP id p12so12762900pgn.6; Wed, 23 Oct 2019 13:02:51 -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=VR7AiOdmDydj8HrBpvMhfZ6ZAfhdNSHVw7PArSxQ9+U=; b=qjt/QIY1TJzaL0nUrb89fYCa6nwOiiO3tOt3NhHlMIS3BViRGj+MeStk4kBMZCUM0r 68JETX725ibNtaFOS+VeJLNBDfkN0M2RrIHLIzMKkbaalQXSiPY3kay9ShuQtePYcpi3 /sFbMOcVhIo9tuMI8Kl1/DJejJK2TdlZDMSPz5hVart/V0ljpb6Wbu+lUykiH09DeVXY c22tSvyX8cKhPVSJpjNGZPSUOWY/+e6USOKfQR7E2w02pUsyHjQG/LC/8C2dYk+0FESp 05kuNOgnU13rcFSyl3KDJ1HLy+UqQS8Ava/8rKYtG8zP4DNpFW9h1l3SOpi0nsvKJLw1 k2JQ== 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=VR7AiOdmDydj8HrBpvMhfZ6ZAfhdNSHVw7PArSxQ9+U=; b=BqlWtsLgraoO150FShx5rWL48y37FbIpUoTJEeWc5sPXq5ofN9fae6IlH81B6Zsb0y Cl1nxGNgTn1LAXaYqXnDX9LO1w92Owc6G+xOXXVmLyO+9TqIT12kC3AI6hSehTMRuf3Q NS3umBJvFt6A+kPPAJnwqZROaZdA8z+TG8ASjsGb5KBayMaCW/86EjmKPXjsJ0C5Jfks ov6rBqfqnLljcRUEKVJTeSAZUlCkdoQm1LUpJ9cyTkXK38CxS0MxEW4zhFFoIi7eAoMw dBJcOctMLOVaJbHPUZkJSh0AHl7Qi7newUY2GFWckV9tIaKYFBE6fK7PTew5i5IG3n93 w0nA== X-Gm-Message-State: APjAAAVOOo/mgNYt4WQrxG1IdSObpdAgwd9nUirfBiekOoPJG6d272jp fWnIk2rDbqhdzVSMWJVM0kg= X-Google-Smtp-Source: APXvYqxfki5pvkdqjt6unEX84WC/q4jHXRwNaHLK/6VltlhWNzlEtvCCyrjp8qIurI8FUWV3bPpScA== X-Received: by 2002:a63:f743:: with SMTP id f3mr12250897pgk.410.1571860970718; Wed, 23 Oct 2019 13:02:50 -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 6sm10593598pfy.43.2019.10.23.13.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:49 -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 v6 07/15] software node: remove property_entry_read_uNN_array functions Date: Wed, 23 Oct 2019 13:02:25 -0700 Message-Id: <20191023200233.86616-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 fd667a73a201..f59dfd01725f 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 Wed Oct 23 20:02:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207477 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 841431515 for ; Wed, 23 Oct 2019 20:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5915821A4A for ; Wed, 23 Oct 2019 20:03:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c58O1Hky" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405576AbfJWUCy (ORCPT ); Wed, 23 Oct 2019 16:02:54 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35380 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405535AbfJWUCy (ORCPT ); Wed, 23 Oct 2019 16:02:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id 205so13597660pfw.2; Wed, 23 Oct 2019 13:02:53 -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=UQeFLa+OhHK62m3xBGQg82d/4If30mhWIdkbN0WgMXc=; b=c58O1Hky20/Vp4ObNl4HQrvnTa7/CGgdXUdt/vPPB+1z4xGS1BpEYh5OEMxuxPZkL7 jqF/lxHdIeUs4TfTh9f6qUCvTUO4rWQbaahp1iETznTye+z9TMAqb2Ls6qRSFoPZcw1a 3EmG0/90kBjZBTtv3s9J5qjAAtA71ghSwyEYwQo9vq/mPNKPNYBiobTe5n5YNWet20tH YHjaQ8WcCWxvDe0BoM7CLw8QXL056TdV/F3MmEgrQeZHL9zjRreFyUdQaVhWrx2to9ul uRlCxQickn9ssgU7PQJnUG/iZesbQYeNbaLwsshcbNnxCikFL0izviY+CbMDadnpuQ32 HLkw== 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=UQeFLa+OhHK62m3xBGQg82d/4If30mhWIdkbN0WgMXc=; b=XLirNvhT0crCM8ss7l7CqUAfyyJS1rTye/ZPkamyTl2vEdLi7pVVpxx51O46i4g6Sc v0lYvXKeOhOCQcgT2ggS8XcdiE+1jZndT+mXCANxHoJevYF1RoJ5l2dgDZfqdXNbzCov 8m87Ints1q71QoERDMTnaWQkhF2EsvMaNRecqrWXT+c+jWJkRNIAp4LAOXod1FSrIaVy Jh50FekSJkynNFwDrcja8mySqmehExjpRGGz8GwBfBjhvUoRloh0AQLMtW6PPdD9whnD dcnjJIX59BmkOq9X7015oJChj7w03OBMxAsfmnOl43I0DY202gzqmo7LzA1mNmxnXM/R /vNw== X-Gm-Message-State: APjAAAVZl9xFWLziwn/P6eT2r5c+OVe2Lpumpp0ua7sRKPMB6qnDMf6d GkkVQYDIp9IGtankmFvvQF7vME1i X-Google-Smtp-Source: APXvYqz6Ta/ZqS0U53REors5qkSUEfg+NsYf0UzqBIFf8w6G0YEhfYt4QKnN+Qu3tus8bZ8r4a0mAw== X-Received: by 2002:aa7:8583:: with SMTP id w3mr13408996pfn.182.1571860972829; Wed, 23 Oct 2019 13:02:52 -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 6sm10593598pfy.43.2019.10.23.13.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:51 -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 v6 08/15] software node: unify PROPERTY_ENTRY_XXX macros Date: Wed, 23 Oct 2019 13:02:26 -0700 Message-Id: <20191023200233.86616-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 12eff7cbb395..48335288c2a9 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -250,37 +250,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_)) @@ -293,30 +289,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 Wed Oct 23 20:02:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207481 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 1230D112B for ; Wed, 23 Oct 2019 20:03:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E18362086D for ; Wed, 23 Oct 2019 20:03:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HWZAI6oU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406276AbfJWUDb (ORCPT ); Wed, 23 Oct 2019 16:03:31 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40107 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405556AbfJWUCy (ORCPT ); Wed, 23 Oct 2019 16:02:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id x127so13590165pfb.7; Wed, 23 Oct 2019 13:02:54 -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=U7yrLgCm1sWsKsLg4PFcTaFGPRuqfSdp4yJRNe14wag=; b=HWZAI6oUd4zj5C+itjIgtiekMAiuAHD1aH14ZRblUi0kgK8bfcauhA0kZFvigeINED o+DET2XYKe39buC3Cm8XwojwxPZUtrWMJlnoiutYxE1FHFfGcgJrw73fLW3iCpf1KHnc Kk5Vpkp5NSowVcuJ+wKorVBX7tSU3vf0UgnbVgX0Blc5wlmprlBEhmgVU8dbuIVhB/bN oXel/TsuRPrnjrHOeQblhSvrGqELeZ9IqsKSjCWLbScuAGJs1KKu67/LgKQRAqDGYyJF yrxafOTOPvCiylFwBfgRibm6ylv7qCOCSnEDlPjcAt4xEREPDCC6xW790hFn/bshZ8Il WSUw== 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=U7yrLgCm1sWsKsLg4PFcTaFGPRuqfSdp4yJRNe14wag=; b=TKoyidKF/bCwwZGsd2cCTSIyFY0vNBR2nurea9qZ6n7HavUBheMNs5GdRlsez2l0VX sA3okagmEHxKJWK2SXSp7gSIF4vZBv59xrP5p6Gnfuo8b7sZBJUM/n+PIS1Vq0IoMFvz k1E44dtZH5xQW+7CmeMmgmFkiaRCctg1zuM2UppMVxvAuQ4uleaAJgIk7qTRYGee8agB Fn62NgEcnFRnARmWF0fv6S8RHUNhB3ysGO6UWri3Mg0mi/DvzCxZRkOOw7RaySY6CaFL mf2z/yF/u737YbHA+nOs4ThpNzrjuweeCR/l4Co+jRHjdFxdrMG6cd7DXW7KXQtc94+J yKkA== X-Gm-Message-State: APjAAAVmsOc9K1iBYaKzBdjT0jOAhd3yzxfuLBKchjs8L7oXLxyfnQ28 CpfcTqaG+M2xm1TbjJXjKtM= X-Google-Smtp-Source: APXvYqxl0S3jmfDiv5LaLLsAIuswlGWVayQhvZbkI3bhz/FCaod8i35vRC9p0hMMKqFMk2b91qtXyg== X-Received: by 2002:aa7:87ce:: with SMTP id i14mr12485376pfo.78.1571860973889; Wed, 23 Oct 2019 13:02:53 -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 6sm10593598pfy.43.2019.10.23.13.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:53 -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 v6 09/15] software node: simplify property_entry_read_string_array() Date: Wed, 23 Oct 2019 13:02:27 -0700 Message-Id: <20191023200233.86616-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 f59dfd01725f..d8d0dc0ca5ac 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 Wed Oct 23 20:02:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207453 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 D1F18112B for ; Wed, 23 Oct 2019 20:03:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A606B21D7E for ; Wed, 23 Oct 2019 20:03:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HKc9L4ff" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406009AbfJWUC6 (ORCPT ); Wed, 23 Oct 2019 16:02:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45234 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405850AbfJWUC5 (ORCPT ); Wed, 23 Oct 2019 16:02:57 -0400 Received: by mail-pg1-f195.google.com with SMTP id r1so12748651pgj.12; Wed, 23 Oct 2019 13:02:56 -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=eQgyOpGt3MaTSbe6tncV8dGOluLEtJp/sHkAMV4YRJY=; b=HKc9L4ffnssmH3G9D7DjyMtDJjPhf+oL/nSPTdFjEJuud45SGoIvbgU4KAlBmoOEPF KOsK+1zYh6idBgqQjns4mx/5xyApMFTUGW/L/JJs2AoxBFifbpjHMPFgIfGA1zI/ih78 8tDGYzvLslIUa7anaTHfRyZ2jGH8hi5Tz9nC65nC8IClnpNp+fl3l1NdyR9CfI3uvgA0 duVKJ9PbTvax1muGaFhtMMuVLgZORmwPruqMZQsmxN9j+8ZW91KkS9L4S2bSl9EnsVWK QpBQYwgJferHPSs6cwoUWm8Ig++uOHVkpsv6Ijis73Liwgsg16ZnsTx0OvWkhxKGoBDr HA6A== 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=eQgyOpGt3MaTSbe6tncV8dGOluLEtJp/sHkAMV4YRJY=; b=VsjhSBt33mnA9iiB1Uk5y5j0igOKSeuOJtPPhNvyJq+Aa7GzdQMSlUiD3T33G5qapC eOxnlx6YvhBYUchlsQW/wX5ASjRRKxNm361a9rwK+GcMLM0UbSl8vXwFSFFVphfqQP9U cgkX16ut1FlGd2R1yfu8R0ItB4q6Ly2S0CmboR/YiSYrJ9IcbdyWFakrhoB+jpoUh0x9 s4zc/q1AFrGnmVcx3y1l2DH3143ljkGo8m/mbUy+nzS3OH2NEzDYHAoAap+dL9NE7XFS fcg9I5PmdV66KE7CABQTzzXhrThuNJzzh3WUqc5KKerg5G2WFaz5CXX3LLKJEN7u3GDG MSww== X-Gm-Message-State: APjAAAWmXIgDqeJ/lbkpyywVrWJArvkf82LYCLPncK5JtSru9cPUA8ZK JOJUByGnl6kZ8r9qzFJjVUU= X-Google-Smtp-Source: APXvYqz391+F4Nnax+RkCJTW/0x+14p9uHQXk2XZRhM4be7avOUZVzrSyOV5xpa1tmtTGYeqzdLu8A== X-Received: by 2002:a62:6842:: with SMTP id d63mr12729066pfc.166.1571860975701; Wed, 23 Oct 2019 13:02:55 -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 6sm10593598pfy.43.2019.10.23.13.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:54 -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 v6 10/15] software node: rename is_array to is_inline Date: Wed, 23 Oct 2019 13:02:28 -0700 Message-Id: <20191023200233.86616-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 | 12 +++++------- include/linux/property.h | 13 ++++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index d8d0dc0ca5ac..18a30fb3cc58 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -108,10 +108,7 @@ static const void *property_get_pointer(const struct property_entry *prop) if (!prop->length) return NULL; - if (prop->is_array) - return prop->pointer; - - return &prop->value; + return prop->is_inline ? &prop->value : prop->pointer; } static const void *property_entry_find(const struct property_entry *props, @@ -205,7 +202,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 +247,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 +261,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 48335288c2a9..dad0ad11b55e 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -227,15 +227,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 embedded 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; @@ -262,7 +264,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_ }, \ } @@ -293,6 +294,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_ } }, \ } @@ -311,6 +313,7 @@ struct property_entry { #define PROPERTY_ENTRY_BOOL(_name_) \ (struct property_entry) { \ .name = _name_, \ + .is_inline = true, \ } struct property_entry * From patchwork Wed Oct 23 20:02:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207455 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 9FEE21515 for ; Wed, 23 Oct 2019 20:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DFFC20663 for ; Wed, 23 Oct 2019 20:03:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VDyBfirf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406288AbfJWUDC (ORCPT ); Wed, 23 Oct 2019 16:03:02 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38579 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405905AbfJWUC6 (ORCPT ); Wed, 23 Oct 2019 16:02:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id w3so12760182pgt.5; Wed, 23 Oct 2019 13:02:57 -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=qkhxgO5jibnlb7gKc/t5p3Tr0Xmy8V6wC17jmmeP1b0=; b=VDyBfirf7hTX/0XDXtmE+/2SNFRPPiCNMhvOaqZ9MgSmlbI5q39XmbT1oHQZTdd2cT 7KigdNosMVhwjJ3M4bVKZboxHtEU/wOY8VYGZoO6xNkT94Yj6kn/4VqGqNQKEjFlX+bt xI5aPv2t/p0wFu0hEd01w95myRHzbReYji3iknCj8WkJKJ1EX46fQXUtlFveQULjZWFt 7636pZlfaU1sImvN7KkfBdoCHoO5NTra/NeQmeVLtET9DwwaE01MYA4ALGRXsGS0o+Qj haVu96qCtMuPo9+rQoOzgfPkZVxC0bAEU1fD+FURS47wb56DQYZRPgdBzRXHpjL6lrIK PAJA== 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=qkhxgO5jibnlb7gKc/t5p3Tr0Xmy8V6wC17jmmeP1b0=; b=K+97ebz08kbPyJXA5fFHvdkmu8EXpcwtxMs2dqEgOLlOYJ+mlJqWA5LxWt8OH+w4hR pAikzrcCUOoMAnjY8ot+lAX+Xr5KJw4Hye2RNBYpNfq8vNnk8DAwvMPygTwjGokLKZMe J/hsgsJfCZCQPkT4X5r3G8KVj7UsQ1H8vSc5zjYPNQt10keUcejNBJJpu5HGgFvcBFAQ +Irn2WHwRK3CqwJQh6Zq5cz/3k0kHnCF9MhxmG29usHrwLhZcpl3W+IKjOh/JHnFFB4G E2I41y1QKXCs56zYDbemEK6bCFK5wA6dvf52FZx68vMkDGaUFKe7qOp0Pq+zo2mE9QbW VGXQ== X-Gm-Message-State: APjAAAXtFnE0cKYma6rgs4AdWO4WCzgjxLc1/VHzeZnIsKTqhv9mrnnz XIVf4r/heoyy4N5u+XbWiEc= X-Google-Smtp-Source: APXvYqxHlIN2pAAFMCYe9L8Yy42MavOeVtrhlKodtX0YyZgHgWr5v5zWh+4rJ2KwNRnpKQYn540vhQ== X-Received: by 2002:a62:61c4:: with SMTP id v187mr12953291pfb.23.1571860976940; Wed, 23 Oct 2019 13:02:56 -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 6sm10593598pfy.43.2019.10.23.13.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:56 -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 v6 11/15] software node: move small properties inline when copying Date: Wed, 23 Oct 2019 13:02:29 -0700 Message-Id: <20191023200233.86616-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 18a30fb3cc58..49e1108aa4b7 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -280,6 +280,16 @@ static int property_entry_copy_data(struct property_entry *dst, if (!dst->name) goto out_free_data; + 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); + } + return 0; out_free_data: From patchwork Wed Oct 23 20:02:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207471 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 C8BCD139A for ; Wed, 23 Oct 2019 20:03:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93F3321A4A for ; Wed, 23 Oct 2019 20:03:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZLhiFraM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407149AbfJWUDZ (ORCPT ); Wed, 23 Oct 2019 16:03:25 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40699 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406276AbfJWUDA (ORCPT ); Wed, 23 Oct 2019 16:03:00 -0400 Received: by mail-pg1-f195.google.com with SMTP id 15so7411826pgt.7; Wed, 23 Oct 2019 13:02:59 -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=2wEJsj2T1McYfPe/3D+nl/orb4+Uhzsc4nT6dIF30Fk=; b=ZLhiFraMR2AMaPxz1nLr0tkxRRvjdeRslFj0W6R4PHIO1hf6YCeK+cvyj1JzJwxoFy Q9vM/dPM253md/0hN9d9q0VsEX8U8V16jS3bHgsv/0ZfKndbHcYo2P+ZIUtdccq3Q0e3 na5YkB5snqAj3UgLx0e6jLxN/EDxNuiC1Dh3KukMCDBf6qmdBbS/DPyGk+igjSwr2uRg BHL8WftXyeNaNpaWmTWHRay2sWHTTvvYfhcnF+VDJh6Wgzrc8eF0ADTlUT56ZF7AGFOM /euKDVSG46s8X1q/U/NUy1bBycpavpOPorc7X1+wIt/QnY8Jk/k9TlYeDYI8ZF/WfiSE lDyQ== 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=2wEJsj2T1McYfPe/3D+nl/orb4+Uhzsc4nT6dIF30Fk=; b=qzaoAPErGry9hBL3yFmQfU6Kz8QsuVZ4xvgBsO3iZgFKYBns4XjWV7coIz5YwjtavR 17xVHQPegimfXbAK+yX1V75dtkBVXxrFzI2yCh6TSjgsQzFNezffbisLjeY1aaCWA6Rk WmnslNCV0MZdKng1OXDxwKAmcQQJY5OOz272yG91qHBaa3m4HqIwZ57J7GcympCwxOmW bLE3UMAEn9/7pC+YGKRJ1pCbROUna3bSoKW+R1vQfQLBS0ms8aupxrI7SqWfRwtGtZ5h yrXOsGVFVSJB430/vYhOiwlhp9+I6X/xfRPMHgyLXc66f2q1l8yrpzCUKnDoMsOISfvZ abIQ== X-Gm-Message-State: APjAAAVzDvfPNMnuj/kKsk67pww9kebn6AfMQB8vFoMtkGUIOI1wMI/I AvHg1v1dpIoi51qjkhHxwjE= X-Google-Smtp-Source: APXvYqyNZ7u4NdFa09zDI6lo99nHFvJwdpfsqQ9dpSUcjl5cgPSWWBbgPY+/vgOrxvRxZmfh0c0IiA== X-Received: by 2002:a17:90a:e285:: with SMTP id d5mr2284431pjz.116.1571860979245; Wed, 23 Oct 2019 13:02:59 -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 6sm10593598pfy.43.2019.10.23.13.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:57 -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 v6 12/15] software node: implement reference properties Date: Wed, 23 Oct 2019 13:02:30 -0700 Message-Id: <20191023200233.86616-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 49e1108aa4b7..8fb4dd532433 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -262,6 +262,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) @@ -492,21 +498,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; @@ -525,7 +557,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 dad0ad11b55e..68655c094b39 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 { @@ -223,6 +224,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. @@ -260,14 +275,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_) \ @@ -278,6 +299,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_)) @@ -289,6 +314,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) { \ @@ -316,6 +343,18 @@ struct property_entry { .is_inline = true, \ } +#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); @@ -379,20 +418,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 Wed Oct 23 20:02:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207457 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 084E9139A for ; Wed, 23 Oct 2019 20:03:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D19AC21D7B for ; Wed, 23 Oct 2019 20:03:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mGb6hwQn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406390AbfJWUDD (ORCPT ); Wed, 23 Oct 2019 16:03:03 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38353 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405850AbfJWUDB (ORCPT ); Wed, 23 Oct 2019 16:03:01 -0400 Received: by mail-pf1-f194.google.com with SMTP id c13so2386689pfp.5; Wed, 23 Oct 2019 13:03:00 -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=gjhlsJTrk3yjtwZmFFBfgAs8UQj1cjuqwXRfQNRo2BE=; b=mGb6hwQnmVdqLFpdOJb+liR0HOp76Ldq61WezKPGPzkkGONOEiKeAZFrjCkBhsUA06 i8XbBcOlj7cV7bUfFOI8RVmWf3DtVTQn26UoV0xsAT9MSzhVOfQPO/IoU168CBxTi8Ac RWwq53ed5b7aHhUkhvkW9E7tHsUtZ+5zxuUYICCZ7WKj/dRTBioFHYpUT7dbA+vpfsRg 2ElzZzaSSbbqP3x1hpvBEAhiVBE4fiMcLsXYyq8aDkiSnvcvk9LcH4XW9FBv8oy64ew0 hc7h1CA7PgvmbX+Xd/RcwVxW9E0KchN1DeypGu98K9UivHgwSXdcFoOv0YE3XBUhoIro eNfA== 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=gjhlsJTrk3yjtwZmFFBfgAs8UQj1cjuqwXRfQNRo2BE=; b=Yte50kS9jsn7bI5PmQT7/3kw8FkJqEHROYGJuF1pw7A+UIXWo9l+7CwmYLpRh+NL3P 6hegNpnMYX6CaoE0Y9aQB8h045VjTRc2AcgpdGJdCflRU0He3yFpuNs7kis5l474qTuH Ica8zm9ytefUsPiTkdobuOENrLV0MLOx65BSwMdttuLKRTXN7Me1iQhIs+OFvolIJ7wd Fhxzs5AVmYccwf8cSmtoK4Lg6aShW/cLeYnffERpXZRRgssb1GJge2kbtbay07L+wyQR /IjVQY7ipOcezJLXnsz2VZsX5U19HA36VIyIa078bXoFWZyrf/2o8EtrwL2Toi8rMlnt f3Kg== X-Gm-Message-State: APjAAAVFZz3lBtTbQUPya8DekUvSf1zMfstcWGYlxUO/su0hIOh6Qfj+ cRJ2Vug13ikO5aGp0a9KqHU= X-Google-Smtp-Source: APXvYqwaT21cftXYR9e3yrmeP1PwYV5Rc7rWr4/uprEQk5XpxejD3abKJzzXeZDfYRbJvp2OJT7UQw== X-Received: by 2002:aa7:98c9:: with SMTP id e9mr13229228pfm.142.1571860980239; Wed, 23 Oct 2019 13:03:00 -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 6sm10593598pfy.43.2019.10.23.13.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:02:59 -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 v6 13/15] platform/x86: intel_cht_int33fe: use inline reference properties Date: Wed, 23 Oct 2019 13:02:31 -0700 Message-Id: <20191023200233.86616-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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. Acked-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- .../platform/x86/intel_cht_int33fe_typec.c | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c index 2d097fc2dd46..04138215956b 100644 --- a/drivers/platform/x86/intel_cht_int33fe_typec.c +++ b/drivers/platform/x86/intel_cht_int33fe_typec.c @@ -36,30 +36,6 @@ enum { INT33FE_NODE_MAX, }; -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 @@ -95,8 +71,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), { } }; @@ -112,6 +98,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"), @@ -119,15 +107,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 }, { } }; @@ -163,9 +157,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) { @@ -177,25 +172,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 Wed Oct 23 20:02:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207461 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 9AAF91515 for ; Wed, 23 Oct 2019 20:03:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7944021D7E for ; Wed, 23 Oct 2019 20:03:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u/cI76IA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406461AbfJWUDD (ORCPT ); Wed, 23 Oct 2019 16:03:03 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45931 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405963AbfJWUDC (ORCPT ); Wed, 23 Oct 2019 16:03:02 -0400 Received: by mail-pl1-f194.google.com with SMTP id y24so6673445plr.12; Wed, 23 Oct 2019 13:03:02 -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=RhGMxD9ZBui9SyjLsOvl3oJZU+AUjLFpiylNO9yBlvg=; b=u/cI76IAPXZqzuflqxh4ezni8rgLEaXy2SfJXyCqUD/CU8y8ALp9fFSejVe0qx0tSC ZgggEDeL4rITVhP3qtbpfKztrhD6FXzBw8eeX68ZHGV+sbEMq6kZC8SzHvm50xU0ckWC TIqINoXiDZMQcyWASucla7uuZ5nuZtBeU6Ce47Dfyko08X5pllemXipb7nuGYbLcrSUq dzm/JVoNqXkzzzAPurQ9jgq5RnmRysuWyR33TIbR51DhzHPawIDAESAtMtbx7o2Ko5Nz sdulCPIQWaIV1+ZfXr1fv/O3RMOxUhjne6slKm0SrUwBxbnfO1FtCToZh1t0xzEoAzMt jQ5Q== 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=RhGMxD9ZBui9SyjLsOvl3oJZU+AUjLFpiylNO9yBlvg=; b=XRgaZw6H4du6FT65PrMNMs9AzkFZQ2id+pdh7fViTk0DIZuRGQe6mAHIJiXugDShbC 2Ht5ns9oFu77LNl7TSfOJjnaRtHMBwAAagfIAzHr7i+8yjoLAW0NdLAqkdbwL8PNjZ08 cX7HItNM8voB08IxL2ajL/DhnmVMZfNKZ92Fmq+h5A6JgYTRef4g9fygMgehltzeD39q B3g7qZFnIL/LAXVSNgyZUnWpYoHuSbVIU7THZElWDzIU1mQeHWkJm6WYkpR0phmLXXBB RYonMiw2ePelcZ+P4IKquz2bjJ0VX9d0toNMkAK2Mseq8SvvOd63omZtBgIRnEc0s+6d YHrQ== X-Gm-Message-State: APjAAAVIdgtvd3wIOX0OwAnCSpwKqijmG1RW/1hgeBs9N4aaR3zoF67i LuEHjb/D6QuI1M3c6ahpAmvDRuWk X-Google-Smtp-Source: APXvYqxw4rcPhUQYF+Z2qcbeF69ICHrw1KkopL29Ae/m4A+amiYDp7quyR+wH+qWvjz33ITblfgEsA== X-Received: by 2002:a17:902:b687:: with SMTP id c7mr11285749pls.116.1571860981357; Wed, 23 Oct 2019 13:03:01 -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 6sm10593598pfy.43.2019.10.23.13.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:03:00 -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 v6 14/15] software node: remove separate handling of references Date: Wed, 23 Oct 2019 13:02:32 -0700 Message-Id: <20191023200233.86616-15-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 8fb4dd532433..87c715648eb6 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -497,9 +497,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; @@ -508,37 +507,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; @@ -557,7 +545,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 68655c094b39..b315fdc0ec28 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -418,30 +418,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); From patchwork Wed Oct 23 20:02:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11207467 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 A38C4112B for ; Wed, 23 Oct 2019 20:03:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64EA621BE5 for ; Wed, 23 Oct 2019 20:03:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IsfAmHYq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405963AbfJWUDT (ORCPT ); Wed, 23 Oct 2019 16:03:19 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39855 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406396AbfJWUDE (ORCPT ); Wed, 23 Oct 2019 16:03:04 -0400 Received: by mail-pl1-f194.google.com with SMTP id s17so10607782plp.6; Wed, 23 Oct 2019 13:03:03 -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=fPlqw3QneFahKZuGUNalIRc+uwgnbxmvxyiIprbsWLQ=; b=IsfAmHYqLYGl/9/hKcqdz9i4kT63GDgeGvGEVtfqYAK+7/3X9Ro80FRtbDcmLNZiZl 53PyQxT+7S6ct4zv5C//rajQfLJ8y670o8psAERpZ0tbAlj72BlZGpZ/L4hQ7IdPcttx vJmzU3w4tdDlPFSYAggHAyX2C83zhqMlHfhfwNiyHcwFePajyXuZcSSt3tYDNPVGFhjP qjJEftqntXiGXtFcTkAaxbZtCTrlVdX4o+a57ZiFioNu7mes2KqhqQKw3QSTh1tzOyx0 RXNljkGsE8pRxehAXzF5OkaKzyGzLl9VC4ndE73884v0t030JaVHai0E2eoxhjS9PFpj /Ffg== 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=fPlqw3QneFahKZuGUNalIRc+uwgnbxmvxyiIprbsWLQ=; b=aCxo1TUvXCmAJsFg8y7SLeBq6aPaKm8sQ/IQPQMKPW4QNIw7gA30YinBREMBH9kO3Y 3XFEDg5iNdz2W0bmNdgFRmhyWtTXimkqq+xSUNjgGax2k5wCp+eO+630rFZmCVGQSjTU T1hW9+cy2TJxGxEXn+msfQ2fJauWbpeLc8a2xOpSrmPduocK9Pgw4lHXyWcGE7gNaYsD ysWdfyk5efiwRsNsPvQpCSBHJJzWWOXJTa28b645Pt1Na7h+auZlgLBjd942VDeRVaOz ltBjjtX+lgwN147CGmSMiBh6Sypf7xIW6b79/1t0oO75zLODny8zhW0qbfWxL6/fxZsZ Whtw== X-Gm-Message-State: APjAAAW3SaYx5HiwmLvMmWxGXkdqxgEj+TnArAE+qWY1evqhxijDqpGA BoK/yZ4FR8HzjODZt0IhlgID5XZY X-Google-Smtp-Source: APXvYqw7dIIPFPd6NJixSQyWE9ld8SLzfybMSrq8IKVKzTMmiX77MWnTOjl8wui+s/9mJt4RUcfC7A== X-Received: by 2002:a17:902:8d84:: with SMTP id v4mr11872724plo.220.1571860982503; Wed, 23 Oct 2019 13:03:02 -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 6sm10593598pfy.43.2019.10.23.13.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 13:03:01 -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 v6 15/15] software node: add basic tests for property entries Date: Wed, 23 Oct 2019 13:02:33 -0700 Message-Id: <20191023200233.86616-16-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191023200233.86616-1-dmitry.torokhov@gmail.com> References: <20191023200233.86616-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This adds tests for creating software nodes with properties supplied by PROPERTY_ENTRY_XXX() macros and fetching and validating data from said nodes/properties. We are using KUnit framework for the tests. Signed-off-by: Dmitry Torokhov --- drivers/base/test/Makefile | 2 + drivers/base/test/property-entry-test.c | 472 ++++++++++++++++++++++++ 2 files changed, 474 insertions(+) create mode 100644 drivers/base/test/property-entry-test.c diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile index 0f1f7277a013..22143102e5d2 100644 --- a/drivers/base/test/Makefile +++ b/drivers/base/test/Makefile @@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o + +obj-$(CONFIG_KUNIT) += property-entry-test.o diff --git a/drivers/base/test/property-entry-test.c b/drivers/base/test/property-entry-test.c new file mode 100644 index 000000000000..d6ac84c8ebd0 --- /dev/null +++ b/drivers/base/test/property-entry-test.c @@ -0,0 +1,472 @@ +// SPDX-License-Identifier: GPL-2.0 +// Unit tests for property entries API +// +// Copyright 2019 Google LLC. + +#include +#include +#include + +static void pe_test_uints(struct kunit *test) +{ + const struct property_entry entries[] = { + PROPERTY_ENTRY_U8("prop-u8", 8), + PROPERTY_ENTRY_U16("prop-u16", 16), + PROPERTY_ENTRY_U32("prop-u32", 32), + PROPERTY_ENTRY_U64("prop-u64", 64), + { } + }; + + struct fwnode_handle *node; + u8 val_u8, array_u8[2]; + u16 val_u16, array_u16[2]; + u32 val_u32, array_u32[2]; + u64 val_u64, array_u64[2]; + int error; + + node = fwnode_create_software_node(entries, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + error = fwnode_property_read_u8(node, "prop-u8", &val_u8); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u8, 8); + + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8); + + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16(node, "prop-u16", &val_u16); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u16, 16); + + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16); + + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32(node, "prop-u32", &val_u32); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u32, 32); + + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32); + + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64(node, "prop-u64", &val_u64); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u64, 64); + + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64); + + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1); + KUNIT_EXPECT_NE(test, error, 0); + + fwnode_remove_software_node(node); +} + +static void pe_test_uint_arrays(struct kunit *test) +{ + u8 a_u8[16] = { 8, 9 }; + u16 a_u16[16] = { 16, 17 }; + u32 a_u32[16] = { 32, 33 }; + u64 a_u64[16] = { 64, 65 }; + const struct property_entry entries[] = { + PROPERTY_ENTRY_U8_ARRAY("prop-u8", a_u8), + PROPERTY_ENTRY_U16_ARRAY("prop-u16", a_u16), + PROPERTY_ENTRY_U32_ARRAY("prop-u32", a_u32), + PROPERTY_ENTRY_U64_ARRAY("prop-u64", a_u64), + { } + }; + + struct fwnode_handle *node; + u8 val_u8, array_u8[32]; + u16 val_u16, array_u16[32]; + u32 val_u32, array_u32[32]; + u64 val_u64, array_u64[32]; + int error; + + node = fwnode_create_software_node(entries, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + error = fwnode_property_read_u8(node, "prop-u8", &val_u8); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u8, 8); + + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8); + + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 2); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u8[0], 8); + KUNIT_EXPECT_EQ(test, (int)array_u8[1], 9); + + error = fwnode_property_read_u8_array(node, "prop-u8", array_u8, 17); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u8(node, "no-prop-u8", &val_u8); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u8_array(node, "no-prop-u8", array_u8, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16(node, "prop-u16", &val_u16); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u16, 16); + + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16); + + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 2); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u16[0], 16); + KUNIT_EXPECT_EQ(test, (int)array_u16[1], 17); + + error = fwnode_property_read_u16_array(node, "prop-u16", array_u16, 17); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16(node, "no-prop-u16", &val_u16); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u16_array(node, "no-prop-u16", array_u16, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32(node, "prop-u32", &val_u32); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u32, 32); + + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32); + + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 2); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u32[0], 32); + KUNIT_EXPECT_EQ(test, (int)array_u32[1], 33); + + error = fwnode_property_read_u32_array(node, "prop-u32", array_u32, 17); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32(node, "no-prop-u32", &val_u32); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u32_array(node, "no-prop-u32", array_u32, 1); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64(node, "prop-u64", &val_u64); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)val_u64, 64); + + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 1); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64); + + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 2); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_EQ(test, (int)array_u64[0], 64); + KUNIT_EXPECT_EQ(test, (int)array_u64[1], 65); + + error = fwnode_property_read_u64_array(node, "prop-u64", array_u64, 17); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64(node, "no-prop-u64", &val_u64); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_u64_array(node, "no-prop-u64", array_u64, 1); + KUNIT_EXPECT_NE(test, error, 0); + + fwnode_remove_software_node(node); +} + +static void pe_test_strings(struct kunit *test) +{ + const char *strings[] = { + "string-a", + "string-b", + }; + + const struct property_entry entries[] = { + PROPERTY_ENTRY_STRING("str", "single"), + PROPERTY_ENTRY_STRING("empty", ""), + PROPERTY_ENTRY_STRING_ARRAY("strs", strings), + { } + }; + + struct fwnode_handle *node; + const char *str; + const char *strs[10]; + int error; + + node = fwnode_create_software_node(entries, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + error = fwnode_property_read_string(node, "str", &str); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, str, "single"); + + error = fwnode_property_read_string_array(node, "str", strs, 1); + KUNIT_EXPECT_EQ(test, error, 1); + KUNIT_EXPECT_STREQ(test, strs[0], "single"); + + /* asking for more data returns what we have */ + error = fwnode_property_read_string_array(node, "str", strs, 2); + KUNIT_EXPECT_EQ(test, error, 1); + KUNIT_EXPECT_STREQ(test, strs[0], "single"); + + error = fwnode_property_read_string(node, "no-str", &str); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_read_string_array(node, "no-str", strs, 1); + KUNIT_EXPECT_LT(test, error, 0); + + error = fwnode_property_read_string(node, "empty", &str); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, str, ""); + + error = fwnode_property_read_string_array(node, "strs", strs, 3); + KUNIT_EXPECT_EQ(test, error, 2); + KUNIT_EXPECT_STREQ(test, strs[0], "string-a"); + KUNIT_EXPECT_STREQ(test, strs[1], "string-b"); + + error = fwnode_property_read_string_array(node, "strs", strs, 1); + KUNIT_EXPECT_EQ(test, error, 1); + KUNIT_EXPECT_STREQ(test, strs[0], "string-a"); + + /* NULL argument -> returns size */ + error = fwnode_property_read_string_array(node, "strs", NULL, 0); + KUNIT_EXPECT_EQ(test, error, 2); + + /* accessing array as single value */ + error = fwnode_property_read_string(node, "strs", &str); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, str, "string-a"); + + fwnode_remove_software_node(node); +} + +static void pe_test_bool(struct kunit *test) +{ + const struct property_entry entries[] = { + PROPERTY_ENTRY_BOOL("prop"), + { } + }; + + struct fwnode_handle *node; + + node = fwnode_create_software_node(entries, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + KUNIT_EXPECT_TRUE(test, fwnode_property_read_bool(node, "prop")); + KUNIT_EXPECT_FALSE(test, fwnode_property_read_bool(node, "not-prop")); + + fwnode_remove_software_node(node); +} + +/* Verifies that small U8 array is stored inline when property is copied */ +static void pe_test_move_inline_u8(struct kunit *test) +{ + u8 u8_array_small[8] = { 1, 2, 3, 4 }; + u8 u8_array_big[128] = { 5, 6, 7, 8 }; + struct property_entry entries[] = { + PROPERTY_ENTRY_U8_ARRAY("small", u8_array_small), + PROPERTY_ENTRY_U8_ARRAY("big", u8_array_big), + { } + }; + struct property_entry *copy; + const u8 *data_ptr; + + copy = property_entries_dup(entries); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy); + + KUNIT_EXPECT_TRUE(test, copy[0].is_inline); + data_ptr = (u8 *)©[0].value; + KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 1); + KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 2); + + KUNIT_EXPECT_FALSE(test, copy[1].is_inline); + data_ptr = copy[1].pointer; + KUNIT_EXPECT_EQ(test, (int)data_ptr[0], 5); + KUNIT_EXPECT_EQ(test, (int)data_ptr[1], 6); + + property_entries_free(copy); +} + +/* Verifies that single string array is stored inline when property is copied */ +static void pe_test_move_inline_str(struct kunit *test) +{ + char *str_array_small[] = { "a" }; + char *str_array_big[] = { "b", "c", "d", "e" }; + char *str_array_small_empty[] = { "" }; + struct property_entry entries[] = { + PROPERTY_ENTRY_STRING_ARRAY("small", str_array_small), + PROPERTY_ENTRY_STRING_ARRAY("big", str_array_big), + PROPERTY_ENTRY_STRING_ARRAY("small-empty", str_array_small_empty), + { } + }; + struct property_entry *copy; + const char * const *data_ptr; + + copy = property_entries_dup(entries); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, copy); + + KUNIT_EXPECT_TRUE(test, copy[0].is_inline); + KUNIT_EXPECT_STREQ(test, copy[0].value.str, "a"); + + KUNIT_EXPECT_FALSE(test, copy[1].is_inline); + data_ptr = copy[1].pointer; + KUNIT_EXPECT_STREQ(test, data_ptr[0], "b"); + KUNIT_EXPECT_STREQ(test, data_ptr[1], "c"); + + KUNIT_EXPECT_TRUE(test, copy[2].is_inline); + KUNIT_EXPECT_STREQ(test, copy[2].value.str, ""); + + property_entries_free(copy); +} + +/* Handling of reference properties */ +static void pe_test_reference(struct kunit *test) +{ + const struct software_node nodes[] = { + { .name = "1", }, + { .name = "2", }, + }; + + const struct software_node_ref_args refs[] = { + { + .node = &nodes[0], + .nargs = 0, + }, + { + .node = &nodes[1], + .nargs = 2, + .args = { 3, 4 }, + }, + }; + + const struct property_entry entries[] = { + PROPERTY_ENTRY_REF("ref-1", &nodes[0]), + PROPERTY_ENTRY_REF("ref-2", &nodes[1], 1, 2), + PROPERTY_ENTRY_REF_ARRAY("ref-3", refs), + { } + }; + + struct fwnode_handle *node; + struct fwnode_reference_args ref; + int error; + + error = software_node_register_nodes(nodes); + KUNIT_ASSERT_EQ(test, error, 0); + + node = fwnode_create_software_node(entries, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + error = fwnode_property_get_reference_args(node, "ref-1", NULL, + 0, 0, &ref); + KUNIT_ASSERT_EQ(test, error, 0); + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]); + KUNIT_EXPECT_EQ(test, ref.nargs, 0U); + + /* wrong index */ + error = fwnode_property_get_reference_args(node, "ref-1", NULL, + 0, 1, &ref); + KUNIT_EXPECT_NE(test, error, 0); + + error = fwnode_property_get_reference_args(node, "ref-2", NULL, + 1, 0, &ref); + KUNIT_ASSERT_EQ(test, error, 0); + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]); + KUNIT_EXPECT_EQ(test, ref.nargs, 1U); + KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU); + + /* asking for more args, padded with zero data */ + error = fwnode_property_get_reference_args(node, "ref-2", NULL, + 3, 0, &ref); + KUNIT_ASSERT_EQ(test, error, 0); + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]); + KUNIT_EXPECT_EQ(test, ref.nargs, 3U); + KUNIT_EXPECT_EQ(test, ref.args[0], 1LLU); + KUNIT_EXPECT_EQ(test, ref.args[1], 2LLU); + KUNIT_EXPECT_EQ(test, ref.args[2], 0LLU); + + /* wrong index */ + error = fwnode_property_get_reference_args(node, "ref-2", NULL, + 2, 1, &ref); + KUNIT_EXPECT_NE(test, error, 0); + + /* array of references */ + error = fwnode_property_get_reference_args(node, "ref-3", NULL, + 0, 0, &ref); + KUNIT_ASSERT_EQ(test, error, 0); + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[0]); + KUNIT_EXPECT_EQ(test, ref.nargs, 0U); + + /* second reference in the array */ + error = fwnode_property_get_reference_args(node, "ref-3", NULL, + 2, 1, &ref); + KUNIT_ASSERT_EQ(test, error, 0); + KUNIT_EXPECT_PTR_EQ(test, to_software_node(ref.fwnode), &nodes[1]); + KUNIT_EXPECT_EQ(test, ref.nargs, 2U); + KUNIT_EXPECT_EQ(test, ref.args[0], 3LLU); + KUNIT_EXPECT_EQ(test, ref.args[1], 4LLU); + + /* wrong index */ + error = fwnode_property_get_reference_args(node, "ref-1", NULL, + 0, 2, &ref); + KUNIT_EXPECT_NE(test, error, 0); + + fwnode_remove_software_node(node); + software_node_unregister_nodes(nodes); +} + +static struct kunit_case property_entry_test_cases[] = { + KUNIT_CASE(pe_test_uints), + KUNIT_CASE(pe_test_uint_arrays), + KUNIT_CASE(pe_test_strings), + KUNIT_CASE(pe_test_bool), + KUNIT_CASE(pe_test_move_inline_u8), + KUNIT_CASE(pe_test_move_inline_str), + KUNIT_CASE(pe_test_reference), + { } +}; + +static struct kunit_suite property_entry_test_suite = { + .name = "property-entry", + .test_cases = property_entry_test_cases, +}; + +kunit_test_suite(property_entry_test_suite);