From patchwork Wed Sep 11 05:12:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11140313 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 96D73112B for ; Wed, 11 Sep 2019 05:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74CB721A4C for ; Wed, 11 Sep 2019 05:13:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qa+8x6Vp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725798AbfIKFMh (ORCPT ); Wed, 11 Sep 2019 01:12:37 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39836 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbfIKFMh (ORCPT ); Wed, 11 Sep 2019 01:12:37 -0400 Received: by mail-pg1-f194.google.com with SMTP id u17so10889012pgi.6; Tue, 10 Sep 2019 22:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G1atqJhw78fooRvvPUE8mHcp9MCaRCFgPOV+0K8V+Tk=; b=qa+8x6Vpu1yfaHZPLziOlsyW0Fut5ENSKVxo78iKAem8KThwudiHFWjAUnPu4svPxU oNKtxEEU/zGFO9apXP2IvAmaRew0YnDJPeNWaDlK++ouxuVibQdawzjlClxAKZCMJoFH tNyBvNnxBdd2Pvqfecd+G1eDYDdALqG/jKvSJHixyEE0DyW4V6EUrk3jsrHkTUt03BrT Iuqsa1BWuSZzJq6KxWW6JmsN1cRmrkf93l6uXGYF6p+UKj+CHQhIfJDVM2GOtXLOBMzb HYlI0QJKAkDKN8dZ5pZtgVbEaGDc4Eq62p+rRK62GIA/fU/xzt0bZ5tL/Sbld4YecQwK K61Q== 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=G1atqJhw78fooRvvPUE8mHcp9MCaRCFgPOV+0K8V+Tk=; b=bmybXtwiZlP3ATnjBoAcWk8mxLP3NSpqmPBMyULfjJvWKyttcXJTD/kdjS9q+dnioO CDsIi91LNa2Ki5jXfRvfXMxc2oYNZWRYHChmodO2a24IktfCxRS8FGvXs9sRqU9+t5x8 mBwKriO6edC/xA4mG4+M3js0YrKdkspg2bVRwwmAlfm5hVcmjBJsIA8H/KviCgL1/EdM bjxElrEy6TyQvWADGPtkmMzDst3bI+nkDIra6X7Ru10SXEdHiybzSGabFLLllL8T4Y2o aX++nEKTl4RSFX0tygXfKVp4K1WtqMeLrkNuigt94HEiM92PMY2OTo8trA9XQxOKhsMd WBNg== X-Gm-Message-State: APjAAAXFMclvpR5tmI8rER9OsHpWUtjkfyV1tJYKQPFb1L0dfzDETA+B eB+/dnORd0vWtw9//vtSYzw= X-Google-Smtp-Source: APXvYqxILVU512XQHtJ1q0HKDLEgPEioGglB+wpPg83nKUNahX4NpAToukPW0svopBQV58lS6l73RQ== X-Received: by 2002:a63:b64:: with SMTP id a36mr31901398pgl.215.1568178756146; Tue, 10 Sep 2019 22:12:36 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id p11sm22011149pff.136.2019.09.10.22.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:35 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 01/14] software node: remove DEV_PROP_MAX Date: Tue, 10 Sep 2019 22:12:18 -0700 Message-Id: <20190911051231.148032-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org This definition is not used anywhere, let's remove it. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/property.h b/include/linux/property.h index 9b3d4ca3a73a..44c1704f7163 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -22,7 +22,6 @@ enum dev_prop_type { DEV_PROP_U32, DEV_PROP_U64, DEV_PROP_STRING, - DEV_PROP_MAX, }; enum dev_dma_attr { From patchwork Wed Sep 11 05:12: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: 11140287 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 CFBB5112B for ; Wed, 11 Sep 2019 05:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD26D222C6 for ; Wed, 11 Sep 2019 05:12:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZyMQSRtk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbfIKFMj (ORCPT ); Wed, 11 Sep 2019 01:12:39 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37632 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbfIKFMj (ORCPT ); Wed, 11 Sep 2019 01:12:39 -0400 Received: by mail-pg1-f194.google.com with SMTP id c17so3137810pgg.4; Tue, 10 Sep 2019 22:12:38 -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=k6hYIyf0TaML+Z8b0g2cj+cgGBKeyruhIX+oPtdlFL8=; b=ZyMQSRtknL+tHgBeAJoAg3mktJtuAT2iufxcJL4qzNvWAjkM0/+Bc0Y9Pxb6ui4IZ9 Z465u96VnwdgUb/0oCoLDEEajc+MpxVq8e6mTlNMa39bA+pcFzw6or43UCn/IJVijAcC HLR+Eo4VpUbL1d8fWj7Ieoqda9zZE1jXZB/F+8/AMyhlZULZBCfGUwmgwcdcQGncXqUX rudKuRCT/Xzw1X5I0neah1v/W5qImprsmJpK3bVCkzafYXfq4wgWSiWXmwK5YkhbGbqy /0Y3te3Yy29BbuW8HcebDG0x/03geR3/EBuhbZBTTH1OsZTRqyS+ca+ObQC0dzbhVJTO tIzQ== 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=k6hYIyf0TaML+Z8b0g2cj+cgGBKeyruhIX+oPtdlFL8=; b=XhfzkT2vkaFXujx++s8fS0IHYRafgjIDFN2lOZTE7UAqNcOq9cGaaVlTr9rSE5tS9w jLz4lHKkbLs+kfqnk26MyMUOXsWN2Cu/VnToZGsTgf0y1ijnz7p9Q7tOF9xao8Q5a241 9vltD+/ByuSsc+JVQ14fNuO1XbluWALjpLrDcYsP4y5arDD2/oJgk8rhVcJgS6aSD2Im DVstktloyjNW+AwgszFzfySPS09V26lbAoTbSAiWahCaCNbS3+Gb/eAOmspTMOwFlbM0 4PQ+RQ0JkdD/JnsBD7pNX1IIwWZu85in+ILzuOO2kOniJsoWO1gj7//cSUS1OjHGiwoD egjQ== X-Gm-Message-State: APjAAAWZiP/D/6g8xeaCuLRKJ790gQrO2XOoWLHoDwWHYSdJQweXup1h WdyvLh8nPQRGtAaWAzc3vvY= X-Google-Smtp-Source: APXvYqw8bDHul8hkgRPv/MMqG5L79aV9OtKiMy2OHKxeJUp0dpSdljt5We2xF8PyHxWd+PIbxtGsLA== X-Received: by 2002:a63:494d:: with SMTP id y13mr31814884pgk.109.1568178758030; Tue, 10 Sep 2019 22:12:38 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id p11sm22011149pff.136.2019.09.10.22.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:36 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus , Ard Biesheuvel Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 02/14] software node: introduce PROPERTY_ENTRY_ARRAY_XXX_LEN() Date: Tue, 10 Sep 2019 22:12:19 -0700 Message-Id: <20190911051231.148032-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Sometimes we want to initialize property entry array from a regular pointer, when we can't determine length automatically via ARRAY_SIZE. Let's introduce PROPERTY_ENTRY_ARRAY_XXX_LEN macros that take explicit "len" argument. Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 45 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index 44c1704f7163..f89b930ca4b7 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -256,33 +256,44 @@ struct property_entry { * and structs. */ -#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \ +#define PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_) \ (struct property_entry) { \ .name = _name_, \ - .length = ARRAY_SIZE(_val_) * sizeof(_type_), \ + .length = (_len_) * sizeof(_type_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = { ._type_##_data = _val_ } }, \ } -#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, U8, _val_) -#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, U16, _val_) -#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, U32, _val_) -#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, U64, _val_) +#define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) +#define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) +#define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) +#define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ + PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) -#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = ARRAY_SIZE(_val_) * sizeof(const char *), \ - .is_array = true, \ - .type = DEV_PROP_STRING, \ - { .pointer = { .str = _val_ } }, \ +#define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = (_len_) * sizeof(const char *), \ + .is_array = true, \ + .type = DEV_PROP_STRING, \ + { .pointer = { .str = _val_ } }, \ } +#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) + #define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ From patchwork Wed Sep 11 05:12: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: 11140291 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 47CCD18A6 for ; Wed, 11 Sep 2019 05:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A5A321A4C for ; Wed, 11 Sep 2019 05:12:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cefw/7Zi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbfIKFMn (ORCPT ); Wed, 11 Sep 2019 01:12:43 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43002 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbfIKFMl (ORCPT ); Wed, 11 Sep 2019 01:12:41 -0400 Received: by mail-pg1-f195.google.com with SMTP id p3so10886491pgb.9; Tue, 10 Sep 2019 22:12: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=qpppCvLTedSBcBa/SOWBn2uRgFrhyeJNWahbBvWHMOc=; b=Cefw/7ZiVx/zPpNSOg/BSK1Sw41PPz7bSptSjbmvQDlg02T9DppRkILPp5PVqS0z6T kIkdnhUtKBkR6NUCs2PSkaIJetGsnIoEbOnll+OE3L2jMU/MAbMCTubZf8QcW/S2PvAr Sw1oyf9pjDoo4V3k9ZNw8Gig3qOXgbKe7aoVqhw/XMu0oKI2XRRgB+LAa2Q6mcRvnJpQ kPSzRkiJRuWLo7iXQw7r2XfPP7uzMEiR2j96nI51w3bW0qj5PN4C6yNnCfbAthiKj4lV i5cdn3Sobp7URjqlrJZzpP8Sd6fvnZX0lX6g64zjIruQXyCct40ctKC4f959eupP5l1m Cnuw== 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=qpppCvLTedSBcBa/SOWBn2uRgFrhyeJNWahbBvWHMOc=; b=PabNT5BBwtJfu3oCP5eWpM8ifrM2zLMuRc2CnWSpAzPrfhMWfj2Gv2/yZJLbwkHuIb vSW4j+xYI7LEWpQdGLdJ8AKBGE6JGYS6cjjtrTUPEaOp8zuWiYP3ko5emfzAFrmP5At8 kkI4lnVeuBR5FB1jDbm3agHpjvv4JGTk6Zizpgrsvd+fs1hqV1AodbedLia0D45L5/5n 9ih4fs8fJl6KwKfJpIrxuydM1A/yBt2YtalwDiZHFRBeti4KqpjwVwwv32HL3a3iwqCy ZxpcQxGKvRE7op4GjLRdl2/fVs3D3Upo1OLwwXLyHxKoauYJnR3ZbZy9BZaTFM0H/PAw QYEg== X-Gm-Message-State: APjAAAWPK+UrSbi1uAiOX4Y3BIisBq+NWdLqSbHsMAS0W8LX9tdfzFVF KaOr2seDS+dg8RXw1T5N4bM= X-Google-Smtp-Source: APXvYqz6ni7eaKI4KkLnbaoGvZuYdYoFnF02n6NwpjEHvihisSURrgC7MVpPNa0S1yQkbF/x2CwQ1w== X-Received: by 2002:a63:c05:: with SMTP id b5mr6541439pgl.415.1568178759963; Tue, 10 Sep 2019 22:12:39 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id p11sm22011149pff.136.2019.09.10.22.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:38 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus , Ard Biesheuvel Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 03/14] efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN Date: Tue, 10 Sep 2019 22:12:20 -0700 Message-Id: <20190911051231.148032-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Let's switch to using PROPERTY_ENTRY_U8_ARRAY_LEN() to initialize property entries. Also, when dumping data, rely on local variables instead of poking into the property entry structure directly. Signed-off-by: Dmitry Torokhov --- 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 Sep 11 05:12: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: 11140289 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 10F1214DB for ; Wed, 11 Sep 2019 05:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D92F721A4C for ; Wed, 11 Sep 2019 05:12:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aOKhu/Fg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbfIKFMn (ORCPT ); Wed, 11 Sep 2019 01:12:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36980 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbfIKFMn (ORCPT ); Wed, 11 Sep 2019 01:12:43 -0400 Received: by mail-pf1-f196.google.com with SMTP id y5so10141857pfo.4; Tue, 10 Sep 2019 22:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qJ3HB3kwHSQpcF0VVVgUC+yVgqtllSPS/hLFVVeWsow=; b=aOKhu/FgvlpfzBrVxolGRuDI6OZp2k5AAfFDQXpsl0ENWTv0I9NYoNdeL64+Ta6cll 1Vw1IO34y08O/Q54xxcJK6KXCclvw+Zbr4DyoROYATUAfYEpPiKPqEwj2WW1yW903V7q qEY5IjMEJ5qx9CGaVm9/BlLWugg5HWtW6uA1hstG+lcxyC/B+so2jmVgz49NRyGLkzk2 H5LrDqmZ6ssSIl64Zza1SVE/mTYs0gROimVZsSSi3wOHVoq+kBD8Xvysn1bWQN2FHAuE 1rf0ZffWw6cOdwWtXomRy06HL2nRokbyKh+thAoAbW45xXontokD6sw7n++onNj3IjTR VqnA== 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=qJ3HB3kwHSQpcF0VVVgUC+yVgqtllSPS/hLFVVeWsow=; b=G0ddP+QcazxZiNBlu4m/kD4mGwAsspnZ5R8868ItehzENNfxk/7BKkPDy/PP9+gMHR HtVkzB74lD/pqpqnIkdJxoYRWPw7sKHz3SmPT6E0v4WpNvFMk+LD2oLy7plZdWhB2Wjm Vu4PbfOSN33SW6mG9kIP12ls8s1ylhbgusvfXOoExFGRIEzsJcVqe/9iYH2CZmk5HhVX rQHXzrOcGkZXhF4ieSB7uYx1xkW+jsW3E2SqoIn9R4UE0f36JUUvpxLgf4WL7e67ZfzH EGIkYrp4wOk5arfABknaVeasDS1EViQau7XSHcQOi/AezoKeAis5LtEMqWRJxTe8PnSS L0fA== X-Gm-Message-State: APjAAAUZTSFBXmBtgXUkm5Ari6VTIq8/m1U+1se9wjs7dxwQpfrZNby+ pyXYNnDgOALQu0pwz5WtrYo= X-Google-Smtp-Source: APXvYqw2QQv8gFiwJYlpURrLEFteUnlxh5e/obq14T/hty9DxLVnVYJYuMFOncT17G3QffPGd29Zdw== X-Received: by 2002:a65:6294:: with SMTP id f20mr31973683pgv.349.1568178761796; Tue, 10 Sep 2019 22:12:41 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id p11sm22011149pff.136.2019.09.10.22.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:40 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 04/14] software node: mark internal macros with double underscores Date: Tue, 10 Sep 2019 22:12:21 -0700 Message-Id: <20190911051231.148032-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Let's mark PROPERTY_ENTRY_* macros that are internal with double leading underscores so users are not tempted to use them. Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index f89b930ca4b7..2c9d4d209296 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -256,7 +256,7 @@ struct property_entry { * and structs. */ -#define PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_) \ +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_)\ (struct property_entry) { \ .name = _name_, \ .length = (_len_) * sizeof(_type_), \ @@ -266,13 +266,13 @@ struct property_entry { } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ - PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ (struct property_entry) { \ @@ -294,7 +294,7 @@ struct property_entry { #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) -#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ +#define __PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ .length = sizeof(_type_), \ @@ -303,13 +303,13 @@ struct property_entry { } #define PROPERTY_ENTRY_U8(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) #define PROPERTY_ENTRY_U16(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) #define PROPERTY_ENTRY_U32(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) #define PROPERTY_ENTRY_U64(_name_, _val_) \ - PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) + __PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) #define PROPERTY_ENTRY_STRING(_name_, _val_) \ (struct property_entry) { \ From patchwork Wed Sep 11 05:12: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: 11140311 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 1BA10112B for ; Wed, 11 Sep 2019 05:13:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED41E21A4C for ; Wed, 11 Sep 2019 05:13:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JhuQTpR3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfIKFN1 (ORCPT ); Wed, 11 Sep 2019 01:13:27 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36981 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726818AbfIKFMp (ORCPT ); Wed, 11 Sep 2019 01:12:45 -0400 Received: by mail-pf1-f196.google.com with SMTP id y5so10141881pfo.4; Tue, 10 Sep 2019 22:12: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=eO8kYN9dCKJpVNrT1gZqNTBkkExiu3MjUltw/zl2pgs=; b=JhuQTpR3cIX4KQCSoGChxjU8n5tf4t0H6tqOQe9DCehfKA86vNh/IFTBSSUfm6wOAO k7MD6LpdLbSLR7CmgOXaL80Ez0LkqO1pPJ0Ojn/6/69IEcivohKaWYD71dwlKUAxkHSK eNP7HxtyY7JmZH7ACvwoeHyrBvXMLG6SZoZWCLiMA5vnnmN66k8Dc5PzeAVL2OEXEMFM ZcXMEChRqV0a4U/AF7w5bytBTews5i7Aqw94AYxhHtjeoSBQUVa2POs+mD9kBNh4COZM pvV4ilEEVCsGPRMM1NzPjvzRDtBijIFRQkpt65M8GMVUi+kQqZ/r66TEdSeWP2k6c1DU C5FA== 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=eO8kYN9dCKJpVNrT1gZqNTBkkExiu3MjUltw/zl2pgs=; b=dV6kQAYAn3KTX46TWUmiTvimBs2pyICaJiHohuxYDp1n1p/9tSomQ6S/pfyXwMtJlc E6GHV5rWHCIbMisPx1U21KwkAxkRAI4slcOMVJAFOaf+kjl/sHtvp+q1VlUV8zI8jCks da8rJuxblin413HGSlDtRT0eGGdRsN6evoJ4N/Dmufr6iHDmqwGRZVUUy/xSnFxuq+Ug n9feBKb7eNTgdz4po26Y7qYK2Kja929VcoE6x646fHT0wnXCRP9FcgEZV0ItjXP5QwrW +5pZYwh1FyiAdCZ4cMN6fOhDkjTc0RN3SBz6C6AO91MFyG255cSQJlveavW0IXwvp8Zo r0xg== X-Gm-Message-State: APjAAAUFtWhk1/tSrw7ZFhzZXlkn0mLt+/DfyermA9dZMfxMLE0hlhtH wt7dHBeaKZoQG6+j1dvOUTQ= X-Google-Smtp-Source: APXvYqzP0qF9m+m375uNm4tLF58AeA5zYrlo+rn232PVTpNnaIA7kpYyCpFWrLBEetDj4tcFNAyXPA== X-Received: by 2002:a62:f80a:: with SMTP id d10mr39536697pfh.98.1568178763022; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:42 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 05/14] software node: clean up property_copy_string_array() Date: Tue, 10 Sep 2019 22:12:22 -0700 Message-Id: <20190911051231.148032-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Because property_copy_string_array() stores the newly allocated pointer in the destination property, we have an awkward code in property_entry_copy_data() where we fetch the new pointer from dst. Let's change property_copy_string_array() to return pointer and rely on the common path in property_entry_copy_data() to store it in destination structure. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index ee2a405cca9a..7bad41a8f65d 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 Sep 11 05:12: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: 11140309 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 E4377184E for ; Wed, 11 Sep 2019 05:13:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B943621A4C for ; Wed, 11 Sep 2019 05:13:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I81PYlpA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbfIKFMp (ORCPT ); Wed, 11 Sep 2019 01:12:45 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43069 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfIKFMp (ORCPT ); Wed, 11 Sep 2019 01:12:45 -0400 Received: by mail-pg1-f196.google.com with SMTP id u72so10881553pgb.10; Tue, 10 Sep 2019 22:12: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=Sr5fjQTMZVqf+Bacd5g9dQg5Ens8+dgwrpyFPkZSOxI=; b=I81PYlpAKX/W2CfW7Na7WdVPXubtkOv2peWrSpwBv00eVnfizb5Io/APJgRPRHQrng lxPWcyQn4Vp66OQUbYoC/Z1/g+XbApeE2Xu6klh7eU8er+qpKAfAlqhNMXxo1Sd5ebsw XVehMx5mb1BdBVCxFOjWh4guC20sOXK8eBEyWi6mHeERZHLFSsLRFMOGy+tNXDTQC+Cn hUZ3AShswkE3hYYOTHKAhSn9uimIMNjysrkAA2wmCB/bdDhyf10wTUiMC4I+J9p7Qkti 8L+vSbxtidYoG9oKoMMIDJ4J66WuCoo6QDJAd7Tq7zLPDPpc4wZFWrMqgFUeo8SWjsnV GShA== 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=Sr5fjQTMZVqf+Bacd5g9dQg5Ens8+dgwrpyFPkZSOxI=; b=d1mfT2/pT8vVRXjFnr0/CO42gzIaNIItpzvq0lvHfKL3XhZkxu9rHOf6pf88xHVZOB UGMJCQpO+M5OO2tn0opV34lpWfo8uNfjO5rJYiQqeXOf01oFMUkKjtbpJH9IUSfwjGbs AgDKiJ3sjpoH+qVRITFgg58sDwxUWq2EexbjVH1GHXl2eSrnRnqO2hGDr4qAXG2V7sS6 l5Y2Auu9FAdSHRll7XnyXY17LsNvNP8O1hncasShqqnRqk4vmGbbEVjjEmnfcNaR2l0i SS4m1njHDFMTUZg9l2LubWBlbsZ1iPar6bWtH2jpB5HGfy0Rm3y0cl8zARbl+fpvcFfJ HN5g== X-Gm-Message-State: APjAAAVRfTsYPSTG8+utqVsjfFE3IqzbP2tBuWn4s+n/pBOdKbTabJrr 5IU+6aQRu8dYU04JZV75orU= X-Google-Smtp-Source: APXvYqxNJTOZbRUEGaipqBNeV3JtfmKsQfW0Y3abDdEsnfzacv6CRpAGh6xhFFjoD6yZOeoi85mhmQ== X-Received: by 2002:a62:7c47:: with SMTP id x68mr40265301pfc.178.1568178764011; Tue, 10 Sep 2019 22:12:44 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id p11sm22011149pff.136.2019.09.10.22.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:43 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 06/14] software node: get rid of property_set_pointer() Date: Tue, 10 Sep 2019 22:12:23 -0700 Message-Id: <20190911051231.148032-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Instead of explicitly setting values of integer types when copying property entries lets just copy entire value union when processing non-array values. When handling array values assign the pointer there using the newly introduced "raw" pointer union member. This 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 raw pointer or pointer to values union. 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 7bad41a8f65d..726195d334e4 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -103,71 +103,15 @@ property_entry_get(const struct property_entry *prop, const char *name) return NULL; } -static void -property_set_pointer(struct property_entry *prop, const void *pointer) -{ - switch (prop->type) { - case DEV_PROP_U8: - if (prop->is_array) - prop->pointer.u8_data = pointer; - else - prop->value.u8_data = *((u8 *)pointer); - break; - case DEV_PROP_U16: - if (prop->is_array) - prop->pointer.u16_data = pointer; - else - prop->value.u16_data = *((u16 *)pointer); - break; - case DEV_PROP_U32: - if (prop->is_array) - prop->pointer.u32_data = pointer; - else - prop->value.u32_data = *((u32 *)pointer); - break; - case DEV_PROP_U64: - if (prop->is_array) - prop->pointer.u64_data = pointer; - else - prop->value.u64_data = *((u64 *)pointer); - break; - case DEV_PROP_STRING: - if (prop->is_array) - prop->pointer.str = pointer; - else - prop->value.str = pointer; - break; - default: - break; - } -} - static const void *property_get_pointer(const struct property_entry *prop) { - switch (prop->type) { - case DEV_PROP_U8: - if (prop->is_array) - return prop->pointer.u8_data; - return &prop->value.u8_data; - case DEV_PROP_U16: - if (prop->is_array) - return prop->pointer.u16_data; - return &prop->value.u16_data; - case DEV_PROP_U32: - if (prop->is_array) - return prop->pointer.u32_data; - return &prop->value.u32_data; - case DEV_PROP_U64: - if (prop->is_array) - return prop->pointer.u64_data; - return &prop->value.u64_data; - case DEV_PROP_STRING: - if (prop->is_array) - return prop->pointer.str; - return &prop->value.str; - default: + if (!prop->length) return NULL; - } + + if (prop->is_array) + return prop->pointer; + + return &prop->value; } static const void *property_entry_find(const struct property_entry *props, @@ -322,13 +266,15 @@ static int property_entry_read_string_array(const struct property_entry *props, static void property_entry_free_data(const struct property_entry *p) { const void *pointer = property_get_pointer(p); + const char * const *src_str; size_t i, nval; if (p->is_array) { - if (p->type == DEV_PROP_STRING && p->pointer.str) { + if (p->type == DEV_PROP_STRING && p->pointer) { + src_str = p->pointer; nval = p->length / sizeof(const char *); for (i = 0; i < nval; i++) - kfree(p->pointer.str[i]); + kfree(src_str[i]); } kfree(pointer); } else if (p->type == DEV_PROP_STRING) { @@ -341,6 +287,7 @@ static const char * const * property_copy_string_array(const struct property_entry *src) { const char **d; + const char * const *src_str = src->pointer; size_t nval = src->length / sizeof(*d); int i; @@ -349,8 +296,8 @@ property_copy_string_array(const struct property_entry *src) return NULL; for (i = 0; i < nval; i++) { - d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); - if (!d[i] && src->pointer.str[i]) { + d[i] = kstrdup(src_str[i], GFP_KERNEL); + if (!d[i] && src_str[i]) { while (--i >= 0) kfree(d[i]); kfree(d); @@ -380,20 +327,21 @@ static int property_entry_copy_data(struct property_entry *dst, if (!new) return -ENOMEM; } + + dst->is_array = true; + dst->pointer = new; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) return -ENOMEM; + + dst->value.str = new; } else { - new = pointer; + dst->value = src->value; } dst->length = src->length; - dst->is_array = src->is_array; dst->type = src->type; - - property_set_pointer(dst, new); - dst->name = kstrdup(src->name, GFP_KERNEL); if (!dst->name) goto out_free_data; diff --git a/include/linux/property.h b/include/linux/property.h index 2c9d4d209296..ec8f84d564a8 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -233,13 +233,7 @@ struct property_entry { bool is_array; enum dev_prop_type type; union { - union { - const u8 *u8_data; - const u16 *u16_data; - const u32 *u32_data; - const u64 *u64_data; - const char * const *str; - } pointer; + const void *pointer; union { u8 u8_data; u16 u16_data; @@ -262,7 +256,7 @@ struct property_entry { .length = (_len_) * sizeof(_type_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ - { .pointer = { ._type_##_data = _val_ } }, \ + { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ @@ -280,7 +274,7 @@ struct property_entry { .length = (_len_) * sizeof(const char *), \ .is_array = true, \ .type = DEV_PROP_STRING, \ - { .pointer = { .str = _val_ } }, \ + { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ From patchwork Wed Sep 11 05:12: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: 11140305 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 0D4CD112B for ; Wed, 11 Sep 2019 05:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D53B621A4C for ; Wed, 11 Sep 2019 05:13:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V2Pl0HTI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbfIKFMr (ORCPT ); Wed, 11 Sep 2019 01:12:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46921 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbfIKFMq (ORCPT ); Wed, 11 Sep 2019 01:12:46 -0400 Received: by mail-pg1-f195.google.com with SMTP id m3so10863201pgv.13; Tue, 10 Sep 2019 22:12:46 -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=E1vVs3Lzody5lrf1o5ZR077jKGjcCEkV/NBzcDZrQso=; b=V2Pl0HTIX2QlLG1iLAkV58snVQjE0MkmuArkqfGK3bYdjoPUwfTe9RnyQ88HJIXhOW TugiuIj5wrWS8dVUbLAwsbnoMXlOsRZn4R3IuaZDgLuT7MXJVFSY7R0TStUse+IMf771 Ed7NBuTKMQvHcIOvVquXo3AKO35x3jUGnV6liXexFVZ9f4DWxDD2GgXeHdE9GMKZKlzx TBfGLo8N+6EhBqosOcXM1hmpc5bo01nMdtIO3gSPBQxawdPi5vSzPpGpyLdJcvIQQvQE 4iWVEPRY4cf+BGoasI/NAApYZc+JXkNxZegfaRYlYqoe2I3q5qLiNSh3an0wsiNcvcCi 9BvA== 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=E1vVs3Lzody5lrf1o5ZR077jKGjcCEkV/NBzcDZrQso=; b=n+0EnpjoT6sM8fInrSwxiRFYp0OmAZnhAzf/ndbFYz075nq2StpH+wqs4oX9OTVSxk u0Gpnrlq38MNJq4iHVqH3FXXYpb+WvA3fUjdg/ZfJg4K1WQW8qMkCRNFbGtw+SZQvb0X nYntGW02uVNOQb5IjJ069yMSJ9aTNDTtx6DOwpVPEfsuHgbYvT+QJq+W1a5d9xeLJKWL KH69FCD06EjXp5FuzrsUY74xZB+/5YT08yFT1H6AAC1FWE6q8EaTLsL1uvrI6ND4CtlL OpRh/fW9EQF/3vrmuSGujqj7oFaQ4FShyPXuHg5quXKxLkHTKzqeCLDWbXRjMdHwCL7i gMHg== X-Gm-Message-State: APjAAAXBymeJhr5FAZjXOW8hNRVbz4s+6Okhdj4j34MyuuspQZAc2ynB vS1AsHf6Qbzm/HH2BhxL2to= X-Google-Smtp-Source: APXvYqzzWqGo9Ae1XocivC2km4QBMwwacG5wThNB7peEYMoUlbV8+7vKWkD6k9xpcSbihHGxKZTNoA== X-Received: by 2002:a17:90a:ff04:: with SMTP id ce4mr3438503pjb.121.1568178765635; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:44 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 07/14] software node: remove property_entry_read_uNN_array functions Date: Tue, 10 Sep 2019 22:12:24 -0700 Message-Id: <20190911051231.148032-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org There is absolutely no reason to have them as we can handle it all nicely in property_entry_read_int_array(). Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 85 +++++++------------------------------------ 1 file changed, 14 insertions(+), 71 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 726195d334e4..a019b5e90d3b 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 Sep 11 05:12: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: 11140307 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 5F61C112B for ; Wed, 11 Sep 2019 05:13:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 343EA21D7B for ; Wed, 11 Sep 2019 05:13:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dLTfU1Ue" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbfIKFNX (ORCPT ); Wed, 11 Sep 2019 01:13:23 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46576 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbfIKFMr (ORCPT ); Wed, 11 Sep 2019 01:12:47 -0400 Received: by mail-pf1-f194.google.com with SMTP id q5so12864124pfg.13; Tue, 10 Sep 2019 22:12:46 -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=WnwWtVtC6uezsNkuF5wmz268WUJO4EZ17z2Uk6qqhWs=; b=dLTfU1UeiL5ZxW1r8ZEpwjgZ5ViCfEc+q+YYgTYl/Y7iJ1pU/GH8RxfGFzW8ymDy48 dHt+J2A9fw4ug8LqvBNkNf2gGU+MNKIf28rRNmxVyGrwVaZXAjhcmciUJVDWijvvdoFQ GD6IS4AHr/GwSEAjl16rxr3VAOLEUT4W+hfS/nZ022f/71LZQxEy6HqIzpFQGCFzyc1H hV+gEqj+y7asSUAOdIR8Kx+nkIlKlk4PIJpF3KA6OnsNi4b5rdz97GEIzoeq3t8ykeKO XpXyaiqMeLDIfeXJGlTbAqGlVHR2Okuxn2uzTXxZIXiFRVp5WIoJ+cxiyApfHD/jXUXk IWMw== 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=WnwWtVtC6uezsNkuF5wmz268WUJO4EZ17z2Uk6qqhWs=; b=MRUCdC9eCcBsIUSfrSFohl1hKqkzp+RwEYeMbGsQwoKRD9p5VEYNuzMtymU+kCZrUS CfBpP6luZVVixnxG1qWxbhxt+flKrsQL9QxLbRrMuui50nmx4V70URVAWKLiBuANTFpU LiIT/ztaGsbetnJ/9JjXl8Si5hHalqNNeTsKZA6/vkCQOq+Ib3ubnHx4IVJ698UH8bvl FVHan3aF+87GyRlOCYs41Wx5KTibBdtj/4ejeDAbznDcE8icLT3Pd9GWzrqts9QjbQRt MYzJBNqIa8k5Clfplm1gboOuNnIdkaUtAHZp0H9UqkGu5KJwwz7KJ4dfrlMWwrhs7oqh TcmQ== X-Gm-Message-State: APjAAAVuRlksVqAU86qt/V8rM/nFU3NzJBL1F9XLkLoUaMv2OU7AtcsX zm2WcG+68H8K9D3wmIzYe5M= X-Google-Smtp-Source: APXvYqwdL0RzFYmbLLzoEArxUZpv4bPMUIKcrTFdLOvuq+s91/MZYaQNKw0JTxmKuQN7Dujs+6mpOQ== X-Received: by 2002:a62:e717:: with SMTP id s23mr40425298pfh.71.1568178766419; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:45 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 08/14] software node: unify PROPERTY_ENTRY_XXX macros Date: Tue, 10 Sep 2019 22:12:25 -0700 Message-Id: <20190911051231.148032-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org We can unify string properties initializer macros with integer initializers. Signed-off-by: Dmitry Torokhov --- include/linux/property.h | 64 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index ec8f84d564a8..238e1507925f 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -245,37 +245,33 @@ struct property_entry { }; /* - * Note: the below four initializers for the anonymous union are carefully + * Note: the below initializers for the anonymous union are carefully * crafted to avoid gcc-4.4.4's problems with initialization of anon unions * and structs. */ -#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _type_, _Type_, _val_, _len_)\ +#define __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_) \ + sizeof(((struct property_entry *)NULL)->value._elem_) + +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ (struct property_entry) { \ .name = _name_, \ - .length = (_len_) * sizeof(_type_), \ + .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8, U8, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16, U16, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_) #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32, U32, _val_, _len_) + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_) #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64, U64, _val_, _len_) - + __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = (_len_) * sizeof(const char *), \ - .is_array = true, \ - .type = DEV_PROP_STRING, \ - { .pointer = _val_ }, \ -} + __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) @@ -288,30 +284,24 @@ struct property_entry { #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) -#define __PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = sizeof(_type_), \ - .type = DEV_PROP_##_Type_, \ - { .value = { ._type_##_data = _val_ } }, \ +#define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .type = DEV_PROP_##_Type_, \ + { .value = { ._elem_ = _val_ } }, \ } -#define PROPERTY_ENTRY_U8(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_) -#define PROPERTY_ENTRY_U16(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_) -#define PROPERTY_ENTRY_U32(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_) -#define PROPERTY_ENTRY_U64(_name_, _val_) \ - __PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_) - -#define PROPERTY_ENTRY_STRING(_name_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = sizeof(const char *), \ - .type = DEV_PROP_STRING, \ - { .value = { .str = _val_ } }, \ -} +#define PROPERTY_ENTRY_U8(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_) +#define PROPERTY_ENTRY_U16(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_) +#define PROPERTY_ENTRY_U32(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_) +#define PROPERTY_ENTRY_U64(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_) +#define PROPERTY_ENTRY_STRING(_name_, _val_) \ + __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) #define PROPERTY_ENTRY_BOOL(_name_) \ (struct property_entry) { \ From patchwork Wed Sep 11 05:12: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: 11140303 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 4676D112B for ; Wed, 11 Sep 2019 05:13:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22F6321D7B for ; Wed, 11 Sep 2019 05:13:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FJt1wbxc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbfIKFNT (ORCPT ); Wed, 11 Sep 2019 01:13:19 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43074 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbfIKFMs (ORCPT ); Wed, 11 Sep 2019 01:12:48 -0400 Received: by mail-pg1-f193.google.com with SMTP id u72so10881640pgb.10; Tue, 10 Sep 2019 22:12:48 -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=Quna5dhwEKx+rAq2g69EwnMLgIT5ImG5uNLk/TAdGE4=; b=FJt1wbxcOvsw1NxaBU/dPTHar140OLodCaSHmQbWZHNYlFmBwM78EnU1Tu5fKNNpO7 A2jihYwwI4L7XryVJjoKZBunJc4LF2LiXXxeHCRuHxnE0adivvy5pi84dXTTfsTh2xzf mEBJyn1zwlQDi2Ht7SLZpVRu1t/xa5I60cE2ifJEW/XV5sosOa94vyaH59aWrLM/ho2u 90aKOWIsEp0YOrYWTV5ZfCU8Y3IIytiTzWVrtgyxBeuDlFunuItxKwBRqMqencksQ8mJ uJd1u2jOnmLUXpMaGnDxTa7937ZWio350zwQ7ye2G7OcPlI1ZSBakJmSd2T5X7HMe9fz i7eQ== 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=Quna5dhwEKx+rAq2g69EwnMLgIT5ImG5uNLk/TAdGE4=; b=CbiyYntYbDgahHWn4BclVmHqNuj1arVoa1kTWKXaOzZ8KQJBlnNYoVI09+WYGSr8Wb 7YheKUKHwyykUNy0MP5kqQXyG3pc6+VHdND+DlSC5VA5p7qZBV4NKiKExXX1RiLq4CvD 21DuqoHVJOPAV2trt4M/rKtCe9FB0frVgTgBOLU8jWdM0ddSV1GoT4lpVkgy6x1XxPga UTEvCI/2KcccW9YO+rvtldDOsv5ORWBmwl0IuTqDI754wJ6lJKt4mQ1e4fx0b2wOhhMu efLyb1/mM0/be8dsoaA2DX7LMN1Z/DEkOHcAOIqCytHGHMv3I+AjiZ3DX5lPPYGXaR3L 2nrQ== X-Gm-Message-State: APjAAAW70JKdrISLP2QPA9Dy1d5tPKI3eYIAVIIUK/2GbLcX7G5Ub/ir DXjdd667b/iRxcyIesAoMoM= X-Google-Smtp-Source: APXvYqw2AREs9xiEQAGYIQXwEB31ZMDQbSji6wbL9i8RjBUltOK8HlwMdV/h44zH9lwK+kXoavYqIw== X-Received: by 2002:a62:1a4d:: with SMTP id a74mr4708634pfa.179.1568178767612; Tue, 10 Sep 2019 22:12:47 -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 p11sm22011149pff.136.2019.09.10.22.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:46 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 09/14] software node: simplify property_entry_read_string_array() Date: Tue, 10 Sep 2019 22:12:26 -0700 Message-Id: <20190911051231.148032-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org There is no need to treat string arrays and single strings separately, we can go exclusively by the element length in relation to data type size. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index a019b5e90d3b..9c3e566c753e 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 Sep 11 05:12: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: 11140301 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 E2CD5184E for ; Wed, 11 Sep 2019 05:13:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C14D921D7D for ; Wed, 11 Sep 2019 05:13:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VFoxoJEc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbfIKFMv (ORCPT ); Wed, 11 Sep 2019 01:12:51 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:32909 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726876AbfIKFMt (ORCPT ); Wed, 11 Sep 2019 01:12:49 -0400 Received: by mail-pg1-f196.google.com with SMTP id n190so10912205pgn.0; Tue, 10 Sep 2019 22:12: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=+lAoewH+jhsvt3QeezehbGtMBLTUm9LftrXq9l91DQ0=; b=VFoxoJEckEcZIGDTxpPt7UGaWMAQrO3tkzFDjvrIZMfM4bK/YZWAu9wd9ILoV0gVBV RmRC2FZKNa2rU/kK/Wl/yoYr/ll+BPWPlT7IiyRtH0y+n1ymHU7ZqsMVz1WZQDwegPki JVazvV4FNcz6T7zE6N1MtKrV7KjKzmOdEUGTbEO0RClpqMrviAhEZlW0V7Hkm3qROx4K OzmcZdr2x0p8+Y5NIHfCBypAvKN8ViuyqCxjhmunkMYv4wz2/JGA6wcVIgGvsI8eSjhp E+483k/AGkQrdjHqIiTBfdtgDWD2dgid34j1eZ9wKkmMwSgsLDD0WFx1Gxr+8GTJ0Evn U4Ow== 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=+lAoewH+jhsvt3QeezehbGtMBLTUm9LftrXq9l91DQ0=; b=gmxBFZ/wyjmA1at/Ixr+5RtJwOZY3cnNon1NK6y9ll3kssSfcJXeFcjetCCs/WRVN2 tIQIhJf8rrVd7AuMwtJWSr1hBN7P2a0yKZWreNPEBh8STzRBHErdpSdCMb9jmB/GfsK9 hKWnVcY62sczQFL9qTMmuXh5JcZAt0foh2WAC7PFhVVyZM3uf+TjQ1SBMb9nem35VMc0 tHoL7oqC4TQYHLTXNq8+BAKM9OYdfx6i5Xg/0z1E1nvesWeAB41ghWuvPGfCDT3A9SEg azL4muDcmajrFpYD8MbQkAkZSErwqMulLmqBQuHv0NDD+XO5Fwe60sWTLK/ZEqV1PWUA cPAw== X-Gm-Message-State: APjAAAUI4S+mYdq3MQrr4HwU3tCfm0M8ojX/ZYEMCrPjLEIv4tmqgrCN 9eByjs9yIrKnfEZvL7hZFtQ= X-Google-Smtp-Source: APXvYqxCtF6ozo7kQje77FWoQfLW4x1y4DZ5T4Y2lgvx2KNuRoeZ1DZU6y2TLJbsZM2AkxWOAr502g== X-Received: by 2002:a17:90b:8d7:: with SMTP id ds23mr3254538pjb.141.1568178768687; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:47 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 10/14] software node: rename is_array to is_inline Date: Tue, 10 Sep 2019 22:12:27 -0700 Message-Id: <20190911051231.148032-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org We do not need a special flag to know if we are dealing with an array, as we can get that data from ratio between element length and the data size, however we do need a flag to know whether the data is stored directly inside property_entry or separately. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 9 +++++---- include/linux/property.h | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 9c3e566c753e..83e2a706a86e 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -108,7 +108,7 @@ static const void *property_get_pointer(const struct property_entry *prop) if (!prop->length) return NULL; - if (prop->is_array) + if (!prop->is_inline) return prop->pointer; return &prop->value; @@ -205,7 +205,7 @@ static void property_entry_free_data(const struct property_entry *p) const char * const *src_str; size_t i, nval; - if (p->is_array) { + if (!p->is_inline) { if (p->type == DEV_PROP_STRING && p->pointer) { src_str = p->pointer; nval = p->length / sizeof(const char *); @@ -250,7 +250,7 @@ static int property_entry_copy_data(struct property_entry *dst, const void *pointer = property_get_pointer(src); const void *new; - if (src->is_array) { + if (!src->is_inline) { if (!src->length) return -ENODATA; @@ -264,15 +264,16 @@ static int property_entry_copy_data(struct property_entry *dst, return -ENOMEM; } - dst->is_array = true; dst->pointer = new; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) return -ENOMEM; + dst->is_inline = true; dst->value.str = new; } else { + dst->is_inline = true; dst->value = src->value; } diff --git a/include/linux/property.h b/include/linux/property.h index 238e1507925f..ac7823d58cfe 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -222,15 +222,17 @@ static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, * struct property_entry - "Built-in" device property representation. * @name: Name of the property. * @length: Length of data making up the value. - * @is_array: True when the property is an array. + * @is_inline: True when the property value is stored directly in + * &struct property_entry instance. * @type: Type of the data in unions. - * @pointer: Pointer to the property (an array of items of the given type). - * @value: Value of the property (when it is a single item of the given type). + * @pointer: Pointer to the property when it is stored separately from + * the &struct property_entry instance. + * @value: Value of the property when it is stored inline. */ struct property_entry { const char *name; size_t length; - bool is_array; + bool is_inline; enum dev_prop_type type; union { const void *pointer; @@ -257,7 +259,6 @@ struct property_entry { (struct property_entry) { \ .name = _name_, \ .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ - .is_array = true, \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } @@ -288,6 +289,7 @@ struct property_entry { (struct property_entry) { \ .name = _name_, \ .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .is_inline = true, \ .type = DEV_PROP_##_Type_, \ { .value = { ._elem_ = _val_ } }, \ } From patchwork Wed Sep 11 05:12: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: 11140299 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 54A68112B for ; Wed, 11 Sep 2019 05:13:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 335FC21D7D for ; Wed, 11 Sep 2019 05:13:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H8THHl0/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726893AbfIKFMw (ORCPT ); Wed, 11 Sep 2019 01:12:52 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43480 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726887AbfIKFMv (ORCPT ); Wed, 11 Sep 2019 01:12:51 -0400 Received: by mail-pl1-f194.google.com with SMTP id 4so9624444pld.10; Tue, 10 Sep 2019 22:12: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=g1cvPRP3bs5HHsjzvaUvkDW77LPWNeyn8DJIQNndimA=; b=H8THHl0/mQmPZ4Ap7qcyQeAxlLKMV2wrAt4pVmbywN46Xk9xe9QqvPKGGWQHiJGUod jFAve0mJ07DTzjFpBCDRVoWxZouHGRY/G0PsgyegKp2ATERJGMhnebjZ0QEwtuBfL7tp 0yFwFQiakZf73ITk7bDalhZxK34nkiioZwCjKG8C8JgR8Iy+grrCSO4hDEMBclcqLApR 1iJQuXHTcxWcty7P1jb2DJRILwj5F8yw3HFHny26OoY9W3MqjaUdV4WsTih4muHi8gWt x11w9RmvI/qOnjUSWox4zJ9mx/prlNN9kOL6co69dBKSybcAhs5HibxvU57KVVDm35kI 32lw== 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=g1cvPRP3bs5HHsjzvaUvkDW77LPWNeyn8DJIQNndimA=; b=iYuQQ9bzUlGR9Av7dWTYr2zZ/3AZYjr8Ak+91KLbQu9aiHpc64l/pD2ayY7pG1eJF5 wlSv3KQ4I3a7/MaozQZzc6BCRb53XqmUkA5R3H5o9JXxfQj+IXGIDheQYVhkpk2LAS7W HHtZeG/JqV20gGo8QzGH3mPPMd6X//3SKi4v7VRps9maEcbXLSo9NNUsXCghi8RdWW5T Or2DLsa6JuXOukIXCzNZEKPB+lail4qZ5RIMWFqH7fWhLvdz9qFIWbotkUnW2OO0D5JO bairqk2UB5FewwYuix6jQZN5OMzsOeqVTu0wHs6PpQctjki4HSctlnEKKr+iwpl7EBEh OXlw== X-Gm-Message-State: APjAAAVx3Jn/eO8bEVG2IdFnOYqJ5ijiHgTRyR4vbvT5+dmP0jXqVErs F7aE78Px/4ywUS2D6fVxjzc= X-Google-Smtp-Source: APXvYqw1hqk7Z4iFGn5pqXwMJ0VKMJWsgTlBIweg7zfdobJL+r1pI2AQ0MGUSMw07DwvHj2B7G8m/w== X-Received: by 2002:a17:902:4a:: with SMTP id 68mr29800569pla.196.1568178770678; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:49 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 11/14] software node: move small properties inline when copying Date: Tue, 10 Sep 2019 22:12:28 -0700 Message-Id: <20190911051231.148032-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org When copying/duplicating set of properties, move smaller properties that were stored separately directly inside property entry structures. We can move: - up to 8 bytes from U8 arrays - up to 4 words - up to 2 double words - one U64 value - one or 2 strings. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 83e2a706a86e..1aa6559993ec 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -277,6 +277,16 @@ static int property_entry_copy_data(struct property_entry *dst, dst->value = src->value; } + if (!dst->is_inline && dst->length <= sizeof(dst->value)) { + /* We have an opportunity to move the data inline */ + const void *tmp = dst->pointer; + + memcpy(&dst->value, tmp, dst->length); + dst->is_inline = true; + + kfree(tmp); + } + dst->length = src->length; dst->type = src->type; dst->name = kstrdup(src->name, GFP_KERNEL); From patchwork Wed Sep 11 05:12: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: 11140297 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 319D014DB for ; Wed, 11 Sep 2019 05:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F142F21D7D for ; Wed, 11 Sep 2019 05:13:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FK55kvaz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726911AbfIKFMx (ORCPT ); Wed, 11 Sep 2019 01:12:53 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40151 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726901AbfIKFMx (ORCPT ); Wed, 11 Sep 2019 01:12:53 -0400 Received: by mail-pf1-f194.google.com with SMTP id x127so12879955pfb.7; Tue, 10 Sep 2019 22:12: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=UM/x9OUxWvKu8h5hlzYT3dDasLYFcLlKN6IsiVi+Sck=; b=FK55kvazx7m5MCBwdSr2PBkhps1PNkE44SkmtGNua/suozgruYUqEs0hkHSF8y06T3 jf/+axjFBGFHMmQCTA+sfpm8D4elE5076HnvbvygiOc7Y/8LWgORHAbKYwcJ/tuiRm5m 0X1nzky7jFSW1P1j5C692CFwtDcxaVnWEk5FDRSrsdbVFONUhUrk15eD531jDiWsDEbp R2UQ7eOfsx8zo6OuV/N9nEBhasiGveaFBjf6z0WhizOSZQ+fbJlae84l2uy8fPxhzPow 4Lcjj0/PCHTa7luy4eKuVL//YuG3x2VLhGhZQymYPpVYUuXPsST7NAq1Lj2jCPTZcSN/ W1tQ== 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=UM/x9OUxWvKu8h5hlzYT3dDasLYFcLlKN6IsiVi+Sck=; b=PzG1aPaO400uL6XtA60oI4Rtq+FbVEDSyyUwn3w3ZrxT1xMRZtgMRPu4ilht4ULKvD CEQo9Hxk0OLlVjyxsXaigt9BgzNI1k72TQcgQABQkhEInhJM3vtskOQ2I7JrcW8CzRz+ u9vge/VRzLFT0SWMFOCfjKXombOa7anWyISY/5KppiLsViWum3ECHlyyO9aCnZCRAeXm gKnnd2FnFY1cviWWZ1cMUFp7jxaBkypLKQD/AEOD4Ug2V5/P4Ep0qkYKF0111QNxsYA8 qvBFarmGa8jSrIAL3SQGvBtm2YswGh8MZ9+VjySquZBpSV/cfOcdsaYNTGtD1taI9LeU 3lIg== X-Gm-Message-State: APjAAAUuCtT8UFuFFsHTOngbM34HZfqvm3lfUci34LkH7nO4fcDoS4uk Tjyo87vmFYnI+QGifbdze5eNiaR2JxQ= X-Google-Smtp-Source: APXvYqxfcYyaPW0OLzaJAMVoWfQd5w98bgB2OI1BVlo6NJfzkteuBKrocfw2Q+/C0T6Ya1Nl0iBWzw== X-Received: by 2002:a17:90a:2206:: with SMTP id c6mr3401556pje.4.1568178772376; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:50 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 12/14] software node: implement reference properties Date: Tue, 10 Sep 2019 22:12:29 -0700 Message-Id: <20190911051231.148032-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org It is possible to store references to software nodes in the same fashion as other static properties, so that users do not need to define separate structures: static const struct software_node gpio_bank_b_node = { .name = "B", }; static const struct property_entry simone_key_enter_props[] = { PROPERTY_ENTRY_U32("linux,code", KEY_ENTER), PROPERTY_ENTRY_STRING("label", "enter"), PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW), { } }; Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 48 +++++++++++++++++++++++++++------ include/linux/property.h | 57 +++++++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 1aa6559993ec..07e1325789d2 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -265,6 +265,12 @@ static int property_entry_copy_data(struct property_entry *dst, } dst->pointer = new; + } else if (src->type == DEV_PROP_REF) { + /* + * Reference properties are never stored inline as + * they are too big. + */ + return -EINVAL; } else if (src->type == DEV_PROP_STRING) { new = kstrdup(src->value.str, GFP_KERNEL); if (!new && src->value.str) @@ -460,21 +466,47 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, { struct swnode *swnode = to_swnode(fwnode); const struct software_node_reference *ref; + const struct software_node_ref_args *ref_array; + const struct software_node_ref_args *ref_args; const struct property_entry *prop; struct fwnode_handle *refnode; int i; - if (!swnode || !swnode->node->references) + if (!swnode) return -ENOENT; - for (ref = swnode->node->references; ref->name; ref++) - if (!strcmp(ref->name, propname)) - break; + prop = property_entry_get(swnode->node->properties, propname); + if (prop) { + if (prop->type != DEV_PROP_REF) + return -EINVAL; - if (!ref->name || index > (ref->nrefs - 1)) - return -ENOENT; + /* + * We expect that references are never stored inline, even + * single ones, as they are too big. + */ + if (prop->is_inline) + return -EINVAL; + + if (index * sizeof(*ref_args) >= prop->length) + return -ENOENT; + + ref_array = prop->pointer; + ref_args = &ref_array[index]; + } else { + if (!swnode->node->references) + return -ENOENT; + + for (ref = swnode->node->references; ref->name; ref++) + if (!strcmp(ref->name, propname)) + break; + + if (!ref->name || index > (ref->nrefs - 1)) + return -ENOENT; + + ref_args = &ref->refs[index]; + } - refnode = software_node_fwnode(ref->refs[index].node); + refnode = software_node_fwnode(ref_args->node); if (!refnode) return -ENOENT; @@ -493,7 +525,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs; for (i = 0; i < nargs; i++) - args->args[i] = ref->refs[index].args[i]; + args->args[i] = ref_args->args[i]; return 0; } diff --git a/include/linux/property.h b/include/linux/property.h index ac7823d58cfe..08d3e9d126ef 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -22,6 +22,7 @@ enum dev_prop_type { DEV_PROP_U32, DEV_PROP_U64, DEV_PROP_STRING, + DEV_PROP_REF, }; enum dev_dma_attr { @@ -218,6 +219,20 @@ static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); } +struct software_node; + +/** + * struct software_node_ref_args - Reference property with additional arguments + * @node: Reference to a software node + * @nargs: Number of elements in @args array + * @args: Integer arguments + */ +struct software_node_ref_args { + const struct software_node *node; + unsigned int nargs; + u64 args[NR_FWNODE_REFERENCE_ARGS]; +}; + /** * struct property_entry - "Built-in" device property representation. * @name: Name of the property. @@ -255,14 +270,20 @@ struct property_entry { #define __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_) \ sizeof(((struct property_entry *)NULL)->value._elem_) -#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ +#define __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, _elsize_, _Type_, \ + _val_, _len_) \ (struct property_entry) { \ .name = _name_, \ - .length = (_len_) * __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .length = (_len_) * (_elsize_), \ .type = DEV_PROP_##_Type_, \ { .pointer = _val_ }, \ } +#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\ + __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ + __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + _Type_, _val_, _len_) + #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ @@ -273,6 +294,10 @@ struct property_entry { __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) +#define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_) \ + __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ + sizeof(struct software_node_ref_args), \ + REF, _val_, _len_) #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) @@ -284,6 +309,8 @@ struct property_entry { PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) +#define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ @@ -310,6 +337,18 @@ struct property_entry { .name = _name_, \ } +#define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \ +(struct property_entry) { \ + .name = _name_, \ + .length = sizeof(struct software_node_ref_args), \ + .type = DEV_PROP_REF, \ + { .pointer = &(const struct software_node_ref_args) { \ + .node = _ref_, \ + .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \ + .args = { __VA_ARGS__ }, \ + } }, \ +} + struct property_entry * property_entries_dup(const struct property_entry *properties); @@ -373,20 +412,6 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -struct software_node; - -/** - * struct software_node_ref_args - Reference with additional arguments - * @node: Reference to a software node - * @nargs: Number of elements in @args array - * @args: Integer arguments - */ -struct software_node_ref_args { - const struct software_node *node; - unsigned int nargs; - u64 args[NR_FWNODE_REFERENCE_ARGS]; -}; - /** * struct software_node_reference - Named software node reference property * @name: Name of the property From patchwork Wed Sep 11 05:12: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: 11140293 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 291B3112B for ; Wed, 11 Sep 2019 05:13:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F298A222BD for ; Wed, 11 Sep 2019 05:13:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ge/EeQoT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbfIKFND (ORCPT ); Wed, 11 Sep 2019 01:13:03 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38430 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbfIKFMz (ORCPT ); Wed, 11 Sep 2019 01:12:55 -0400 Received: by mail-pl1-f194.google.com with SMTP id p9so4913274plk.5; Tue, 10 Sep 2019 22:12: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=gm/hCgpnzaPrHHZ/aR0dzYOcB5B3Hpj/g7rPPbjysyo=; b=ge/EeQoTSdNzd/rNC2nGLo/0qQUgNcs86a8i8BAd4VD52vlRii1Og0wgaMBNJV9Y5+ l0ewhWqj+gIH8H23D6luD1mx0/ZOVxwC+WquAkxJ+90WOvSyHGab6Ji0hjIYr6b7y6Re QIPdiACXjzLaGxhj5evNMv6Fo/qTzSgbuOx3wgHxPirFr2z2CuV8QsR49D5V6txz3aWw HxcaWv2mNvw5ZsQmtVFKVlASxnfu2w0HM53E+fiu+dj8A7FLgnigRzYEf5UI2yxjXH/z 98vbU90hhMSOhhNxgzUo3iOCPiB4qvBhJJSYaIFruS5hyjNdDyNVTYy0r+YQyZTK6VOC e5/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gm/hCgpnzaPrHHZ/aR0dzYOcB5B3Hpj/g7rPPbjysyo=; b=cewHXIQXv3dxRucn40hFEFijiF5MMGOEwwxIp/BXGM+uF0fl2Q6ZF+HOthLG9KdlYH eQ9fwUf1vZ2acRDqyS0irdvJ4EuC29lSz4dpG5/K7T4G1NnLPIV7EYtCTr4jtD1W1Sf/ FuLHwzRQT4n0GdUUxhwW7n4Iu6xWI//7p4IoPfsW5wuVr/bSsFrQgHLUk148CyAAR3xu UonQa2xAFWexZ15Tqj2kVSYIPK1SbBFIMdgSFpXkn0c7LdnC7o4ovRL8YMu49L4UMao0 01EvzltL5O1UwKg39hIwLT655oFeCuUugYZijm2eWUEsh3+K4PtaMZFVWo6bfn7KXDdb IKUg== X-Gm-Message-State: APjAAAV9nnTtV0Kdf951TwvItFkoZv2h66q1tP6t/I4KfjmEbuQSVrhV 28FDZRt7+xbSlJ+kk+FyTCA= X-Google-Smtp-Source: APXvYqxCN8xHj1/tJrUJLanYOX5QM8tQ7EGhpG/qJaI0k1L87m1Llsg1JAnyL2f1gPvGXM9+1aLFRA== X-Received: by 2002:a17:902:bd05:: with SMTP id p5mr33681188pls.339.1568178773116; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:52 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 13/14] platform/x86: intel_cht_int33fe: use inline reference properties Date: Tue, 10 Sep 2019 22:12:30 -0700 Message-Id: <20190911051231.148032-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Now that static device properties allow defining reference properties together with all other types of properties, instead of managing them separately, let's adjust the driver. Signed-off-by: Dmitry Torokhov --- drivers/platform/x86/intel_cht_int33fe.c | 81 ++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/platform/x86/intel_cht_int33fe.c b/drivers/platform/x86/intel_cht_int33fe.c index 1d5d877b9582..4177c5424931 100644 --- a/drivers/platform/x86/intel_cht_int33fe.c +++ b/drivers/platform/x86/intel_cht_int33fe.c @@ -46,30 +46,6 @@ struct cht_int33fe_data { struct fwnode_handle *dp; }; -static const struct software_node nodes[]; - -static const struct software_node_ref_args pi3usb30532_ref = { - &nodes[INT33FE_NODE_PI3USB30532] -}; - -static const struct software_node_ref_args dp_ref = { - &nodes[INT33FE_NODE_DISPLAYPORT] -}; - -static struct software_node_ref_args mux_ref; - -static const struct software_node_reference usb_connector_refs[] = { - { "orientation-switch", 1, &pi3usb30532_ref}, - { "mode-switch", 1, &pi3usb30532_ref}, - { "displayport", 1, &dp_ref}, - { } -}; - -static const struct software_node_reference fusb302_refs[] = { - { "usb-role-switch", 1, &mux_ref}, - { } -}; - /* * Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates * the max17047 both through the INT33FE ACPI device (it is right there @@ -105,8 +81,18 @@ static const struct property_entry max17047_props[] = { { } }; +/* + * We are not using inline property here because those are constant, + * and we need to adjust this one at runtime to point to real + * software node. + */ +static struct software_node_ref_args fusb302_mux_refs[] = { + { .node = NULL }, +}; + static const struct property_entry fusb302_props[] = { PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"), + PROPERTY_ENTRY_REF_ARRAY("usb-role-switch", fusb302_mux_refs), { } }; @@ -122,6 +108,8 @@ static const u32 snk_pdo[] = { PDO_VAR(5000, 12000, 3000), }; +static const struct software_node nodes[]; + static const struct property_entry usb_connector_props[] = { PROPERTY_ENTRY_STRING("data-role", "dual"), PROPERTY_ENTRY_STRING("power-role", "dual"), @@ -129,15 +117,21 @@ static const struct property_entry usb_connector_props[] = { PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo), PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo), PROPERTY_ENTRY_U32("op-sink-microwatt", 2500000), + PROPERTY_ENTRY_REF("orientation-switch", + &nodes[INT33FE_NODE_PI3USB30532]), + PROPERTY_ENTRY_REF("mode-switch", + &nodes[INT33FE_NODE_PI3USB30532]), + PROPERTY_ENTRY_REF("displayport", + &nodes[INT33FE_NODE_DISPLAYPORT]), { } }; static const struct software_node nodes[] = { - { "fusb302", NULL, fusb302_props, fusb302_refs }, + { "fusb302", NULL, fusb302_props }, { "max17047", NULL, max17047_props }, { "pi3usb30532" }, { "displayport" }, - { "connector", &nodes[0], usb_connector_props, usb_connector_refs }, + { "connector", &nodes[0], usb_connector_props }, { } }; @@ -173,9 +167,10 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) { software_node_unregister_nodes(nodes); - if (mux_ref.node) { - fwnode_handle_put(software_node_fwnode(mux_ref.node)); - mux_ref.node = NULL; + if (fusb302_mux_refs[0].node) { + fwnode_handle_put( + software_node_fwnode(fusb302_mux_refs[0].node)); + fusb302_mux_refs[0].node = NULL; } if (data->dp) { @@ -187,25 +182,31 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) static int cht_int33fe_add_nodes(struct cht_int33fe_data *data) { + const struct software_node *mux_ref_node; int ret; - ret = software_node_register_nodes(nodes); - if (ret) - return ret; - - /* The devices that are not created in this driver need extra steps. */ - /* * There is no ACPI device node for the USB role mux, so we need to wait * until the mux driver has created software node for the mux device. * It means we depend on the mux driver. This function will return * -EPROBE_DEFER until the mux device is registered. */ - mux_ref.node = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); - if (!mux_ref.node) { - ret = -EPROBE_DEFER; - goto err_remove_nodes; - } + mux_ref_node = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); + if (!mux_ref_node) + return -EPROBE_DEFER; + + /* + * Update node used in "usb-role-switch" property. Note that we + * rely on software_node_register_nodes() to use the original + * instance of properties instead of copying them. + */ + fusb302_mux_refs[0].node = mux_ref_node; + + ret = software_node_register_nodes(nodes); + if (ret) + return ret; + + /* The devices that are not created in this driver need extra steps. */ /* * The DP connector does have ACPI device node. In this case we can just From patchwork Wed Sep 11 05:12: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: 11140295 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 E308514DB for ; Wed, 11 Sep 2019 05:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B841C222BD for ; Wed, 11 Sep 2019 05:13:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FyjemSJM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726941AbfIKFNI (ORCPT ); Wed, 11 Sep 2019 01:13:08 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41301 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbfIKFMy (ORCPT ); Wed, 11 Sep 2019 01:12:54 -0400 Received: by mail-pl1-f196.google.com with SMTP id m9so9635758pls.8; Tue, 10 Sep 2019 22:12: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=6w91CiKWHTialn6fseIE4gTrIyeigf6ggLtTvkFJIKY=; b=FyjemSJMxy/U8XOLLnqIZck8AI+Td/HVn+NwGWka0d96bGaEQL0KaDpsmD8/oq1Eys hCVHFUQWfahgBYvba86gkLWAmB8wLJMHtlosjSMGS79ifpEwQcIH+yfczrmgByh41AcP WKImcXQmGnKwPMQJtk3Q0E4LtTagyAJyi7WMXVpd8Tp2hZKc2pRQQGn/RH0sWYi1FMdK MQ50RapkkNAxbiZzwpR85B4M1FlM6KOpaCpj6NzCIPPcB+uZKBYo9mQ+woJx3rFCcqRb hpCMiKJFJtNyO2TuWhGqnf2syV8LG4Gkc3CWC2Y2Sv0d6ETozxoVp84EGwHA+LgHFFeZ pxow== 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=6w91CiKWHTialn6fseIE4gTrIyeigf6ggLtTvkFJIKY=; b=EqPPgMo2RQ2vTMQJtmmUR36QhhGL3A3BmWltgU6NjP6pbkEEVpgr28rkbSnBAQ5/jC dRUysTWzWLFO8E6MUSDbE2u2d09thakmnoiDvnndI2W2N02OqYcaywW/DKbnGaiNrWrn fopr4mPbNe88kTwyNu2tekVJRZeR8y33PQAMz9O+HjIAP8OGsApsqKJaZwD9CGpVBvHJ MNyvaH+q7dBvxAMInEkK9us5GqAH0R8IxhfiMNGNdT/8pUB214Sypn9mVo24xPJRDx0Y 20hD4WPhW612WTgM9nPA5zeVWnwI1Nw4nakRpTQ2Sghu+0vihqQwUw6BsA4X7ATOw5uf KTVw== X-Gm-Message-State: APjAAAUpJPF+HMEwaYgwawTWqt00j7Xi/AZIWOcStQbEjAD0HhIuqYIZ QH0Td3hQvUphP/KnUoi/4zw= X-Google-Smtp-Source: APXvYqxGakxPXGq1e65D6to0gO8Kc4pNMKMuBULrtF40Z0xjNkFjHWqWFtW17+yQ5iOjPXv9E/yPnQ== X-Received: by 2002:a17:902:7285:: with SMTP id d5mr34438830pll.115.1568178773870; Tue, 10 Sep 2019 22:12: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 p11sm22011149pff.136.2019.09.10.22.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 22:12:53 -0700 (PDT) From: Dmitry Torokhov To: "Rafael J. Wysocki" , Heikki Krogerus Cc: Andy Shevchenko , Linus Walleij , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v4 14/14] software node: remove separate handling of references Date: Tue, 10 Sep 2019 22:12:31 -0700 Message-Id: <20190911051231.148032-15-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190911051231.148032-1-dmitry.torokhov@gmail.com> References: <20190911051231.148032-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Now that all users of references have moved to reference properties, we can remove separate handling of references. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 46 +++++++++++++++------------------------- include/linux/property.h | 14 ------------ 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 07e1325789d2..ef38ea9f730b 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -465,9 +465,8 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, struct fwnode_reference_args *args) { struct swnode *swnode = to_swnode(fwnode); - const struct software_node_reference *ref; const struct software_node_ref_args *ref_array; - const struct software_node_ref_args *ref_args; + const struct software_node_ref_args *ref; const struct property_entry *prop; struct fwnode_handle *refnode; int i; @@ -476,37 +475,26 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, return -ENOENT; prop = property_entry_get(swnode->node->properties, propname); - if (prop) { - if (prop->type != DEV_PROP_REF) - return -EINVAL; - - /* - * We expect that references are never stored inline, even - * single ones, as they are too big. - */ - if (prop->is_inline) - return -EINVAL; - - if (index * sizeof(*ref_args) >= prop->length) - return -ENOENT; + if (!prop) + return -ENOENT; - ref_array = prop->pointer; - ref_args = &ref_array[index]; - } else { - if (!swnode->node->references) - return -ENOENT; + if (prop->type != DEV_PROP_REF) + return -EINVAL; - for (ref = swnode->node->references; ref->name; ref++) - if (!strcmp(ref->name, propname)) - break; + /* + * We expect that references are never stored inline, even + * single ones, as they are too big. + */ + if (prop->is_inline) + return -EINVAL; - if (!ref->name || index > (ref->nrefs - 1)) - return -ENOENT; + if (index * sizeof(*ref) >= prop->length) + return -ENOENT; - ref_args = &ref->refs[index]; - } + ref_array = prop->pointer; + ref = &ref_array[index]; - refnode = software_node_fwnode(ref_args->node); + refnode = software_node_fwnode(ref->node); if (!refnode) return -ENOENT; @@ -525,7 +513,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs; for (i = 0; i < nargs; i++) - args->args[i] = ref_args->args[i]; + args->args[i] = ref->args[i]; return 0; } diff --git a/include/linux/property.h b/include/linux/property.h index 08d3e9d126ef..fa5a2ddc0c7b 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -412,30 +412,16 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -/** - * struct software_node_reference - Named software node reference property - * @name: Name of the property - * @nrefs: Number of elements in @refs array - * @refs: Array of references with optional arguments - */ -struct software_node_reference { - const char *name; - unsigned int nrefs; - const struct software_node_ref_args *refs; -}; - /** * struct software_node - Software node description * @name: Name of the software node * @parent: Parent of the software node * @properties: Array of device properties - * @references: Array of software node reference properties */ struct software_node { const char *name; const struct software_node *parent; const struct property_entry *properties; - const struct software_node_reference *references; }; bool is_software_node(const struct fwnode_handle *fwnode);