From patchwork Mon Sep 9 08:15:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137425 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 ED34A16C1 for ; Mon, 9 Sep 2019 08:16:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3A892086D for ; Mon, 9 Sep 2019 08:16:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l1zbtjlN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388870AbfIIIQD (ORCPT ); Mon, 9 Sep 2019 04:16:03 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41813 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388847AbfIIIQC (ORCPT ); Mon, 9 Sep 2019 04:16:02 -0400 Received: by mail-pf1-f195.google.com with SMTP id b13so8651527pfo.8; Mon, 09 Sep 2019 01:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tM14s0DFQFvn+p08YZ3Gzff4jwLvWMH3sDRP998EEe0=; b=l1zbtjlNTcCfGuB2BPlx0CCPS2BgWuciSFZTwah2ar4UzjmoFT+pfeALgQFP20NpH+ OHYGbcnahax+eAJmN8rVNhrg1uz2R0JhsUzYNN6GnL2DtmREu6iteTHlUUxOrlFqohel +e26iuqDBt7rGsyEg7mg3iT5wW62LKDXfbkvjx/l0/4r9vWh87HHrTAJAUh35MrE8jTq +h8t31TgHPHCOhy6FdTdaa39SlCPhURrdvwUy/vhaSnpU+zCauMGdl6s7RNLP8PHcC3R +iDpS7laxNZSNSq6nA5Wlcg/sfEaH/YBdakfFqnS3KLPK3G3jzBGCcrErkLtHioFmqHu cAnw== 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=tM14s0DFQFvn+p08YZ3Gzff4jwLvWMH3sDRP998EEe0=; b=h1e3G+CMZMghDooFF81erXnCzTh5S36axR0ycTiIlpEDVp94HTi+WKNQ67HfP+lVwd nxW9OYHhdprpSPt0rFNyc1LbOyuqMYelDAAINjsUOihENisTds9MYsnWXV5xlTJZB4nU M/qEQ+hEwyUUDLOmFbiXbYqQXXv1I68c/zEL/6Yq4fUHSocdLFlLVCf4vxs02meXt0k8 QYrWTlHGVSghW6oaNTx7X+YWsTugAOiJk26rba4d7WD5aiODwIiBlTCEIZb5+F3WgiUp mgiuZqCBm/BhnRB6GEMq0Iev54jGBl5s4QTD0WTjC5rg3UKsXadUAnpJLsHHwivlNojz FPDA== X-Gm-Message-State: APjAAAU+NqfOxaIRjS+YezO0jBR646HWdzXsgYHi2sosfdcf8f2Z2jqM 4mulB8MYZCZXMc4gUqMomXw= X-Google-Smtp-Source: APXvYqzNTki9MhlLJ8oddpZFdewZ2OsUA3erBamP9wTEDCEiHASEGqMYPmX0Psd5OG54iXPO2/5Cpg== X-Received: by 2002:aa7:9a5b:: with SMTP id x27mr25347691pfj.232.1568016961854; Mon, 09 Sep 2019 01:16:01 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id u65sm12686669pfu.104.2019.09.09.01.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:01 -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 v3 01/13] software node: remove DEV_PROP_MAX Date: Mon, 9 Sep 2019 01:15:45 -0700 Message-Id: <20190909081557.93766-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 Signed-off-by: Dmitry Torokhov Reviewed-by: Andy Shevchenko --- 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 Mon Sep 9 08:15:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137401 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 1A6EB1395 for ; Mon, 9 Sep 2019 08:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E54C520678 for ; Mon, 9 Sep 2019 08:16:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dedZSRuC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388897AbfIIIQF (ORCPT ); Mon, 9 Sep 2019 04:16:05 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38789 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388894AbfIIIQF (ORCPT ); Mon, 9 Sep 2019 04:16:05 -0400 Received: by mail-pg1-f194.google.com with SMTP id d10so7379858pgo.5; Mon, 09 Sep 2019 01:16:04 -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=1NaGIdifoHoi5DE8UKrKYLjoFcMpvhfjVaM5arPhhJQ=; b=dedZSRuCxvBtNKqMlhNtJ9Mv6MXa8vFcQIkGB9h+GKgF+urQR6PjlTYF5D7tcgiRxL +0QFdz/+FnFzi14dgllD4FIhFqfeh02GjSE80OKWiolLPCJAPKbL0lF1xBe6YXvwST+0 gXwwAYZDMJ3S3USCdqCG4CmsHtbIQXdjt14AHsCKiiuuof7R596taP/i5dDePZM6cz7I gnsyTBfQd1W2SCGT02lpFIKtP42ISxVZ68Cu9gL37WYJ0e5v+W4pXCWYat3iQ3RPVKmi APp5cfhcvXKDD9lTQjCNmtcx89RHKFXQnHXoRpW8WsLiQ/eRlv7wPv9kP55iGt5GJ5RV XpMQ== 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=1NaGIdifoHoi5DE8UKrKYLjoFcMpvhfjVaM5arPhhJQ=; b=rHeefabNxf64VoHTFVL49/PFoQ0WLNLEk8b6anaRkwdJ+sxAMR3lDM/dvZXppJrFDc cqFtTrOHwlU5UWKE4pFqrehcEBCysOJ8zLQccOw3OfRyOhiXZm44gAepGetgKl5pMLCz RcF89+K/hzsujG1WwpgjycVY5bWCOsbiWxjapUFkcx2heYD4SLd55pdPJlGZfOeSuOmw YpZ74RYi2h8I/QAQdjJuqRFDBm+SBfUfmYtfVMOcmUdH3bChqE/qC7r5paswvtXYwdpA LeYq22aepO8zOG/9/k9rXwX8bGvAUivT4b8gIufplZqP5PQM++nPD9La4sJLNlwFIwzP nZ6Q== X-Gm-Message-State: APjAAAXRYlX+33qOFlogjzgF+7AWts18qWFty1JIuZKZz3exv5kZxnTG Daosmo28v7BLk/4Uw2km/88= X-Google-Smtp-Source: APXvYqxV8z1N8yFextKJa8+KzcBC+66SKHPqSxeN5GMbIyYQZN2N2xUPasPAOu7Ek3MH0hdmb6hEXg== X-Received: by 2002:a63:204b:: with SMTP id r11mr20453931pgm.121.1568016963971; Mon, 09 Sep 2019 01:16:03 -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 u65sm12686669pfu.104.2019.09.09.01.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:02 -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 v3 02/13] software node: clean up property_copy_string_array() Date: Mon, 9 Sep 2019 01:15:46 -0700 Message-Id: <20190909081557.93766-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 Mon Sep 9 08:15:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137423 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 BD4E916C1 for ; Mon, 9 Sep 2019 08:16:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92C5B2086D for ; Mon, 9 Sep 2019 08:16:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IB0+oaHA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388918AbfIIIQJ (ORCPT ); Mon, 9 Sep 2019 04:16:09 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36234 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388905AbfIIIQH (ORCPT ); Mon, 9 Sep 2019 04:16:07 -0400 Received: by mail-pf1-f193.google.com with SMTP id y22so8686635pfr.3; Mon, 09 Sep 2019 01:16:06 -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=ygERPEYDl5khdxtFV71ZgBn42XfY3vLVBUhlCDUWTi8=; b=IB0+oaHAnB2IEqov32d4DaABRray/YsR+DTNfwBp3QyqA9tttJgXZX2rrHHI4x74zr UABS7aQN8+/CvZ4Hb5KIIeP0X3J55u82Ea3r0C1QRurXtS55ldXJ0ZMO/r3B24X8V+yz A8X8znO1tUCGFyqdQIwDizl9v26KNx+joIr03lLuT8L15RyOnlrAOmCOq8sF5WzTCYu3 3gjR7q7dTbM1Yq2rRxoeiN/n2MQlqVgc9LcYitcejyjJqVXWtunJUmdWc1DniJuCTGvX TYPpJroc5fjJFqtY5mfNm6vbW2yK+VA1q6iP7zXlX5AV6FW5IQEZQCN6e+KC2EdgO5mz 5KAQ== 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=ygERPEYDl5khdxtFV71ZgBn42XfY3vLVBUhlCDUWTi8=; b=M+vS39RS+FH7hBIWc6X+ulQkI1RTr+uk5pG/KwGwN4ofpUSMSNqcgC0PS/XRSrBZ28 D8+aBnfW3FV7gsCpYcYp8CI6rA6a/ZAPo+cKGNO0pHgUrG9hCZAUAcj+o8M6LOd39CmJ fiwDuaC2pKMBrMuWWUl4YvuVnp3wc62f4xGopAlYLWN3Gk5WSGfHHZJzXY6oCpXSMlvB vifuoLtaiw0hnR2aPwAMbRwUNT9+/dJtl2FSRczptpFR/T2KRaNprFzwTJCjenb37iGT c9BnpSJNq8F4WN1xSouYb1JtHj4rcZ6s3HL08+sxKlIxZ/hR4LyXsHzOvABfRA5tw2rF JUlA== X-Gm-Message-State: APjAAAWUafIvLBxk8P/AqGxygIxgajnJ8+PF7LLuM45Ischykh9Ohi9/ S+LwIvUW0PdyovnQGLMHxkM= X-Google-Smtp-Source: APXvYqzEXckrT+EdMdUIs1QKgYUg+AgkH3qbZgV+l+UGHnMxIl2f3qG/fqXXL/LZACKoG3JPkuBq/g== X-Received: by 2002:aa7:8b01:: with SMTP id f1mr26960241pfd.173.1568016965972; Mon, 09 Sep 2019 01:16:05 -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 u65sm12686669pfu.104.2019.09.09.01.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:04 -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 v3 03/13] software node: get rid of property_set_pointer() Date: Mon, 9 Sep 2019 01:15:47 -0700 Message-Id: <20190909081557.93766-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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(). Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 50 +++++----------------------------------- include/linux/property.h | 1 + 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 7bad41a8f65d..a8d12046105e 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -103,45 +103,6 @@ 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) { @@ -380,20 +341,21 @@ static int property_entry_copy_data(struct property_entry *dst, if (!new) return -ENOMEM; } + + dst->is_array = true; + dst->pointer.raw = 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 44c1704f7163..4943b40d3536 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -239,6 +239,7 @@ struct property_entry { const u32 *u32_data; const u64 *u64_data; const char * const *str; + const void *raw; } pointer; union { u8 u8_data; From patchwork Mon Sep 9 08:15:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137421 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 389AE16C1 for ; Mon, 9 Sep 2019 08:16:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FD162086D for ; Mon, 9 Sep 2019 08:16:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CPwFmX/k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389142AbfIIIQm (ORCPT ); Mon, 9 Sep 2019 04:16:42 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33241 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388894AbfIIIQJ (ORCPT ); Mon, 9 Sep 2019 04:16:09 -0400 Received: by mail-pg1-f196.google.com with SMTP id n190so7396125pgn.0; Mon, 09 Sep 2019 01:16:07 -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=KsgRNFOCDuIZ11czAPgOqHyEf7Ffyioe5wChnknAWcs=; b=CPwFmX/k6223gC6lxq0CVIqaai8IZGQVXc+n5Pi2h9gZHb1rVL2j25Bcp34l6YF6Mc +ab4eIz0sX3I3C4qR6zr4/u15xuZ1VDPuW8sm5vql1pdM0zuSFnnwXQoiTstXKS9TU/S u9xJQpLyFK49Xa8QpHCJq9ByqdHurFrWruPrjGdiq2dlgG3HVRDalPvGOc2mI3scaE7K K51qzp7b4tW93/WirZS77nM+wLch8Fa3xpbIE3NsZXB3Dc7vK7lmIDwYVPg/fJtfzInu GRujdjsFGe7/b+7L6sxr/mFZDRys1vUCme2bxR7jEjXhVnYL5g4ZRzCy+6Xu/ED/Ad1S JPKw== 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=KsgRNFOCDuIZ11czAPgOqHyEf7Ffyioe5wChnknAWcs=; b=SkhvufKuAzxLDk5HpBr76x1m8BVAozQci7imZuYtfc8lPsNNA9Ha6zT355WQ7PKJiC JteoZDNom28kE2YA0z8nFR0noseAON3Jf7470yAD8yXXHL0u5sTjLiJx7Vlh4lEjMoU9 cYndTVlhFoM8MDFTWWtGW3lH0JFuxR81aUHVr/qfCZ1JvdMmeZoSoCkv7s7f0j8WnHGg TjYhwBaLyUMP1eLGshqEIKQvnsqe/MXfIQAKwvqeUOzMD+wESbh2fEY+Fbwd5HTMxrNV x7bNBnBfceF7rbs2AZ8y2m4MGADoTRzIT9CHNYJl4VrJggNyz34p7rQ+kJqjYMdkkj+S KFlA== X-Gm-Message-State: APjAAAXjMrVQRODX3JQa9X7RULm3IPRAWOv3atR2dRswHU9sigwncKHf ST0XkFIbq727hbbummDv/CVd+bOHfUo= X-Google-Smtp-Source: APXvYqwygXmyzpqW2sKjwn/gui2KPWp0UkRNk2iptbPf9j3be4dzy96fYpNF7Rqm/G0gK55MAnyHyw== X-Received: by 2002:aa7:9343:: with SMTP id 3mr25821006pfn.145.1568016966653; Mon, 09 Sep 2019 01:16:06 -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 u65sm12686669pfu.104.2019.09.09.01.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:06 -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 v3 04/13] software node: simplify property_get_pointer() Date: Mon, 9 Sep 2019 01:15:48 -0700 Message-Id: <20190909081557.93766-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 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 | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index a8d12046105e..bedc26189bed 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -105,30 +105,13 @@ property_entry_get(const struct property_entry *prop, const char *name) 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.raw; + + return &prop->value; } static const void *property_entry_find(const struct property_entry *props, From patchwork Mon Sep 9 08:15:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137419 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 032021395 for ; Mon, 9 Sep 2019 08:16:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE0D42086D for ; Mon, 9 Sep 2019 08:16:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jE+X37pV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388937AbfIIIQm (ORCPT ); Mon, 9 Sep 2019 04:16:42 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41621 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388916AbfIIIQJ (ORCPT ); Mon, 9 Sep 2019 04:16:09 -0400 Received: by mail-pg1-f195.google.com with SMTP id x15so7371489pgg.8; Mon, 09 Sep 2019 01:16:08 -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=vdFrF4kqXfmGSe2ALsY5G2nBL3lyWxDSNKJUbnUAk5Q=; b=jE+X37pVimPNz8wxNG/xCcqLPw36+vaR+nviOmlSI7B6OGNc8BdZfKM0O8tTKkItLF pDpwNLK/bZBp6Hl3vq+TeKufOnCVq2XAo50lFM0r5zBsbDpsJ5z7T9uG858VlQSXDCJC dpiEY8mLoEcnpzT5+q1iGoXJwr3H9zF4awIWvO1t8KDGV2IIbu+Kni6xrg0BQZTMvrc2 uC9VI+Qe9swDRw57tcnR7wqgMVJK1qkCClGFLG9LIk27SECWU4LX7xwM4UQmyNaN+0Kq 6JUoIjHKTlw0ngo+asoV7zoXQQsEeHPvFsmri9Kbf1PN/WD+qM6KUn8X2Xv2sJzd2Ovs rSow== 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=vdFrF4kqXfmGSe2ALsY5G2nBL3lyWxDSNKJUbnUAk5Q=; b=QLxnC76yAQIuiLHwyOJsldZT66zIr49QU6/7QySXimEMHZpUE8ZcwPzZp4HlpiM+6p wvqRzSg3OoYFNRon7aPnafo3x420lTPqEKCydtNOLSbXmUmr+NolIqXdMiJJGIoQUD1W brvem1h2E7+PZaGxAiARNcPZx8Bk6x/3vBt6jTlPMtzcak4f9oKQ8KuYyivscYU8KGO3 322zkX46D5KD1Hts6X14RSy3RzFBiYnEjQlBnDMyhmTKgl7flIsal8IBPCBhv8SA/xSb 5osmTzBPwk6dNgePyCE/o0bP+zOejrwUwxhlZE5+stTn2LEIsxcxbE70gI8ZZ3H06bMz DRiQ== X-Gm-Message-State: APjAAAUpjVdnVCTPgQveZn8eljWmwX6LCFawtNpKhlBmHxuTJ4Fe5z4l 7za/kw8yUzrm77e9gwF1u9k= X-Google-Smtp-Source: APXvYqysTwLG9wNm1R6USqSGzJzOoGG9ZxL+ksUkqDLcbdnr4hk7dDyMwM2DxhgnW1PSf9WLPxKZcA== X-Received: by 2002:a63:de07:: with SMTP id f7mr21017561pgg.213.1568016968349; Mon, 09 Sep 2019 01:16:08 -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 u65sm12686669pfu.104.2019.09.09.01.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:06 -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 v3 05/13] software node: remove property_entry_read_uNN_array functions Date: Mon, 9 Sep 2019 01:15:49 -0700 Message-Id: <20190909081557.93766-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 bedc26189bed..a0629365972d 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 Mon Sep 9 08:15:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137417 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 4681B1395 for ; Mon, 9 Sep 2019 08:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DCA92086D for ; Mon, 9 Sep 2019 08:16:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YMu453yh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388944AbfIIIQM (ORCPT ); Mon, 9 Sep 2019 04:16:12 -0400 Received: from mail-pl1-f181.google.com ([209.85.214.181]:39217 "EHLO mail-pl1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388905AbfIIIQL (ORCPT ); Mon, 9 Sep 2019 04:16:11 -0400 Received: by mail-pl1-f181.google.com with SMTP id bd8so6185411plb.6; Mon, 09 Sep 2019 01:16:10 -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=yuGs0hz5CxIzty752gFKYk0HsyobjL4IUQwm2G4SX64=; b=YMu453yheSlqaOZcSDBv25kKyEMmOOnXyz7xuaMjSZro6TUTELOyphiG1vdeX7usOD kg7SbhTGTBTGzh5Y58/m0JOfhYQzkGz3kNaylO/KAjC2JOcoARZwL2N9uXILXZyhiDx8 65Y6thXAoNswbzDlpEeLA7I9U1z8123uOwfRldgA0ay3OcPv7BtQ9FQk11L1GH3ASp2/ A9iWi5xabhq5w77qoPjtrNebPu2SLPy9BqC1TeQgJGxFVS4Bf/qOnYtqADiE0Mvfesao GhMemqGDQlHv/aYKc6px+9cFanOHdQCQDnNCchVZ9i61knUfIpbMsybQiSjE+FOXaizb z8sA== 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=yuGs0hz5CxIzty752gFKYk0HsyobjL4IUQwm2G4SX64=; b=IM/nl00QRhzeyEsY/vz/FaTSvqmyHxqXWq83U2BU3uRv1yaeqbUpPS47OyPNWlxAFQ 5NT5DlKzfhIJvjp9g7mPUf1KIRm9oqUKJM38rAvOdmAmcEi/LAPUZWMhOUeqMYOSAcT0 x1WA4YGNqPvY6MMUVRJcRV0oHFxPepPM6LrrdmTOmhkriLfq3vtPUhqKBBDaoNgJVjgC g2IO/GPr7tbp7nN3V38eLvbFleRPE+0BkyFngrQZCTBhuV4J6+M5H9L1owFTGN1mdF3b J2YFcZIuE3+TkxCmJ6IQCEISIsNAEH9dztRIdko2SIoNv4gHq1RcDJGgeAi1QNC6Qvw4 FUjg== X-Gm-Message-State: APjAAAX1UJketaBVgBhcfxVgyxRM+3xFWeRFz0h+aQwJgYWaWzxS2R22 CcJ6JN2Zr/3khoLNEpHSm6Y= X-Google-Smtp-Source: APXvYqxUZpku1eu2kZBcGXOGS50scBfF7DPE+BRqiU68g6jFAvCpf52phqxufxvb71erV/+aD1P1Dw== X-Received: by 2002:a17:902:7296:: with SMTP id d22mr22627115pll.179.1568016970236; Mon, 09 Sep 2019 01:16:10 -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 u65sm12686669pfu.104.2019.09.09.01.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:08 -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 v3 06/13] software node: unify PROPERTY_ENTRY_XXX macros Date: Mon, 9 Sep 2019 01:15:50 -0700 Message-Id: <20190909081557.93766-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 | 70 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/include/linux/property.h b/include/linux/property.h index 4943b40d3536..911ace267247 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -257,57 +257,47 @@ struct property_entry { * and structs. */ -#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \ +#define PROPERTY_ENTRY_ELSIZE(_elem_) \ + sizeof(*(((struct property_entry *)NULL)->pointer._elem_)) + +#define PROPERTY_ENTRY_ARRAY(_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ - .length = ARRAY_SIZE(_val_) * sizeof(_type_), \ + .length = ARRAY_SIZE(_val_) * PROPERTY_ENTRY_ELSIZE(_elem_), \ .is_array = true, \ .type = DEV_PROP_##_Type_, \ - { .pointer = { ._type_##_data = _val_ } }, \ + .pointer._elem_ = _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_STRING_ARRAY(_name_, _val_) \ +#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, u8_data, U8, _val_) +#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, u16_data, U16, _val_) +#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, u32_data, U32, _val_) +#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, u64_data, U64, _val_) +#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, str, STRING, _val_) + +#define PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _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_INTEGER(_name_, _type_, _Type_, _val_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = sizeof(_type_), \ + .length = PROPERTY_ENTRY_ELSIZE(_elem_), \ .type = DEV_PROP_##_Type_, \ - { .value = { ._type_##_data = _val_ } }, \ + .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 Mon Sep 9 08:15:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137415 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 19A7B16C1 for ; Mon, 9 Sep 2019 08:16:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4ADC218DE for ; Mon, 9 Sep 2019 08:16:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O7XU/JSn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388961AbfIIIQN (ORCPT ); Mon, 9 Sep 2019 04:16:13 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37611 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388946AbfIIIQM (ORCPT ); Mon, 9 Sep 2019 04:16:12 -0400 Received: by mail-pg1-f193.google.com with SMTP id d1so7380637pgp.4; Mon, 09 Sep 2019 01:16:12 -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=tME0Q4cNinqlG8VwvZjBQfALZ3g9avp+5J7AvfOF0Ik=; b=O7XU/JSnZyh0ihNBIabyaeKW8xwilNoaMj+dCaSbM1saIjrQCKvE7vbjYLLm6Yza/A g3aXAeCoddq4Cv8leAH4E/SuQBlHWA8DuBRQKMhnlymy12LeYQwM5skDrlc5b/9e2KLU KsD3gSJHST7hvQ8P9IKEs/cUMeyZ/+IlxStHkRtsGqmhtqxVr6OvmdPLnhqWloNekMx5 Zb+9CPCasy0zj0vhIs4WG/r9Ss1aGMkXimpXEydrJSdDWDd5+snjs+NSaj718h5XM6NP Ra1B50tYl2k9Q0kfSVUJSkB1g7rB1nTvy4I5nDiUJyX3eEyj5qcouvoeACXXAcCFgJxh xfjA== 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=tME0Q4cNinqlG8VwvZjBQfALZ3g9avp+5J7AvfOF0Ik=; b=HhoEDwjGkl9/LLvPV79MQ1cQWUaBntASx7XrZAUYf+nsk+XRsSkJDhb9tIHeH6RhuV f83hez2z92umPmKVqQ2VTdUqfbaAryPDC/G89jz9uxjQ1M/Uyz4w26xByhzENCxNySTz bXamJbwGREtCf0OB1PGAXuxbwrXECq7wkFQH3IyXokUaQx8HAa7j69WTIsLVw3zIgrgu ByNOrbDSkaYqRp0g7wddIbs6myItE34vYEZzCjg3KW/DdHWNrgRbc1yYQ1XfFYrL809v /gscC6/OboVlv2snWW2DxaCwKD0WIau2TnoDDUMItSD6VsAWor3KXVwcMZDENFEeuquY yLnQ== X-Gm-Message-State: APjAAAXKrfcNIJgls/JjdRwc32m8K782Man+4VmHZB54gsoQxo9/9e3E 0YUFEYz3tPKcg25RDkw42fU= X-Google-Smtp-Source: APXvYqzBHUwYwhNM18kBXsaeIfdEuaNX4tWsi3xnMBedSuY72okTuyhvxcUKWdN+CKWF3wtMtwryVA== X-Received: by 2002:a17:90a:fa3:: with SMTP id 32mr24277488pjz.35.1568016971873; Mon, 09 Sep 2019 01:16:11 -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 u65sm12686669pfu.104.2019.09.09.01.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:10 -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 v3 07/13] software node: simplify property_entry_read_string_array() Date: Mon, 9 Sep 2019 01:15:51 -0700 Message-Id: <20190909081557.93766-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 a0629365972d..2dfeeab919d4 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 Mon Sep 9 08:15:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137411 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 5281316C1 for ; Mon, 9 Sep 2019 08:16:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2967A21A4C for ; Mon, 9 Sep 2019 08:16:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sq6dXyBV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388946AbfIIIQP (ORCPT ); Mon, 9 Sep 2019 04:16:15 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43793 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388970AbfIIIQO (ORCPT ); Mon, 9 Sep 2019 04:16:14 -0400 Received: by mail-pg1-f195.google.com with SMTP id u72so7364116pgb.10; Mon, 09 Sep 2019 01:16:14 -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=l9SexI8nasVLgeuYZYcGyM3Easa+d7jbfdU+iQ5eqQk=; b=sq6dXyBVTiW5dDplPWSvVD0Cb99T91Vj2r/kBxYePgU/RnGsn5aATmKiTvRWk0acDI GoF26DGwsNPtoqsH5EuOSAfZF62iyAe5tLoMzrH11VcBXqcvWGsCkDFSKIQwfnmlUVvT 2gYb9gXbz+f2EDJOGRJ0Tl3hJItQ7Se65I6xYWwcbStMq66OR8sDZmVBjthRdUbbAtp4 bSnaf6E5n2KDkMNVs5eBE6YjZTAXvozRJNn2sEFGhMk8fzpDK1eJLmvsH4aFl2xA05Ya ZZaD6jXU3LDPIIsg0kOr5ZDMstuKhGisQ655AW0I6inMp2sb6hVOtOujF7iXKkUxBud6 /rIg== 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=l9SexI8nasVLgeuYZYcGyM3Easa+d7jbfdU+iQ5eqQk=; b=e0EzOIyFLw6r8x0g3eSWNo8oGW8PmM5v8ZqqBCxPEIMUeb1OtWTfWFmAWnuXCd/7/r oTG6Dk/Uibn21fmtFKTfgwnSn1PBbD9HK/tvszIVAZtGjOTliCo7tgbZbszizewIh/Xz lVWLqIEQJNhnZQ0Cz29rdH8Tummc4WGpGJOjuDBerSF5vc5xuzXsoIstPhC/oqrFhxW7 3+dWzG83Nz6v12oE5xaSo2jdmRJ4B7h2Rd6M08JLDxZH/S/VUUvDbUoA2V4WIRR4iLBu QjY71loNapf09yRNVdl3K3YfPPc8gEAmtwdO3vo8N8tcCEtAMtFv6Rm5dCi2j5IGIt4d ubgA== X-Gm-Message-State: APjAAAVwZSAb0L6ndgJS338BuS+GT+Bd59z6rnbBUpqSlj3OQ5Cabv7X sAaDr/ktgxSX20c+0qMpK0U= X-Google-Smtp-Source: APXvYqzsr9e/FIkGAUX7UV75DQNvUOtMF3SkGBzhgOChHGSUEE8KjIW8KEsdRVapfbZEmwppgoE/DA== X-Received: by 2002:aa7:91d3:: with SMTP id z19mr26081486pfa.135.1568016973523; Mon, 09 Sep 2019 01:16:13 -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 u65sm12686669pfu.104.2019.09.09.01.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:12 -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 v3 08/13] software node: introduce PROPERTY_ENTRY_ARRAY_XXX_LEN() Date: Mon, 9 Sep 2019 01:15:52 -0700 Message-Id: <20190909081557.93766-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 911ace267247..793d05cbc3b2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -280,6 +280,25 @@ struct property_entry { #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_ARRAY(_name_, str, STRING, _val_) +#define PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = (_len_) * PROPERTY_ENTRY_ELSIZE(_elem_), \ + .type = DEV_PROP_##_Type_, \ + .pointer._elem_ = _val_, \ +} + +#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_) \ + 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_data, U32, _val_, _len_) +#define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ + 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_ELEMENT(_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ From patchwork Mon Sep 9 08:15:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137413 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 881FB1395 for ; Mon, 9 Sep 2019 08:16:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F07A21A4C for ; Mon, 9 Sep 2019 08:16:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dz5jlN7i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387572AbfIIIQf (ORCPT ); Mon, 9 Sep 2019 04:16:35 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37098 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388905AbfIIIQQ (ORCPT ); Mon, 9 Sep 2019 04:16:16 -0400 Received: by mail-pf1-f195.google.com with SMTP id y5so5926220pfo.4; Mon, 09 Sep 2019 01:16:15 -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=GUa+m3FqZ99xfkyvEvlA6sMFSjuli7hMMJB1FS1WyOg=; b=dz5jlN7i8loJALpN2oPiFnyUwtzjMWoePCx4bcpkm2tGDuitkABg0fXZ0YRwuJdpIQ 4nxPD9xwy8javXgn5rJx16BCQpktjYRnb6HA+mT66OcXbYy7VmE0DQZAM3wPJJUySUgT R4vrRCTQAwNVUH/x868egLo0t6zvesjwXi82uVL0FouZCCZNb2/WGixiRVcGIqF70S8I 85k/pcxrXwBkY0xHlKHLDDIf2uns8+MRRQTHHw1X2tPJi64sLG+9SoWz2wJWbV16UuzM G41cDfYInsQpi278kX9veGOrIkHqZvfngu31/r+NTE1W5e28+XWSgwJYzkmrmlwxxgzj kJeA== 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=GUa+m3FqZ99xfkyvEvlA6sMFSjuli7hMMJB1FS1WyOg=; b=rjURnKSDB/nlKlIFWFLvH28xOl/Qqe4dmVFeFRgHB3Hmw6eUo9o97OoGhYOYeJKRAe xC/VIVESKdcwHiFXqRH/f1N+dz7L+YTA8McOP495u3s5d5VYDijQ+H/EyMfbCZtyqK2q 9AblyPQD4PTm7lJqQeTWV7e8L4u+DVqsdnb2AVGl9t4ujWJGF5ahUOcVLD3GS0jKVJFC c6SURiMtAxYLb/MboyQ9Fx80rfQ5/sgzi5H8CN+eDSuWzUPm1NM+6mR4gQEoywKCDjvQ mmoIDcLCFMsATpBSfD1+jcyp+U+x2Ou+neAqUfsfXKDBpd4F8btiawkuNuShG8GBtWfL ZyiQ== X-Gm-Message-State: APjAAAUgXzWdk+WYB7CnZWG4pvY7qEzV59XSkbDLazNDT4OSsEFrXcx1 ccGd1YG/zHzR5q7O6KmGyZc= X-Google-Smtp-Source: APXvYqwU+lBn9p5HKygncaZkZeE12EpPAorple9LCeLGsPhjVwYrznNyh1luLVWSFLNN5qbHA5ivzg== X-Received: by 2002:a63:f941:: with SMTP id q1mr20756332pgk.350.1568016974903; Mon, 09 Sep 2019 01:16:14 -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 u65sm12686669pfu.104.2019.09.09.01.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:13 -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 v3 09/13] efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN Date: Mon, 9 Sep 2019 01:15:53 -0700 Message-Id: <20190909081557.93766-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 instead of poking into the structure directly. Signed-off-by: Dmitry Torokhov --- drivers/firmware/efi/apple-properties.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c index 0e206c9e0d7a..6a09174979b0 100644 --- a/drivers/firmware/efi/apple-properties.c +++ b/drivers/firmware/efi/apple-properties.c @@ -85,11 +85,9 @@ 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[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, + ptr + key_len + sizeof(val_len), + val_len - sizeof(val_len)); if (dump_properties) { dev_info(dev, "property: %s\n", entry[i].name); From patchwork Mon Sep 9 08:15:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137409 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 8170916C1 for ; Mon, 9 Sep 2019 08:16:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5880921A4C for ; Mon, 9 Sep 2019 08:16:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ljypQiWm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388970AbfIIIQS (ORCPT ); Mon, 9 Sep 2019 04:16:18 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:32895 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388998AbfIIIQR (ORCPT ); Mon, 9 Sep 2019 04:16:17 -0400 Received: by mail-pf1-f196.google.com with SMTP id q10so8686671pfl.0; Mon, 09 Sep 2019 01:16:17 -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=x4ns4T+1S1k8Yfl1+HirB82I68GDEC4NojYLSrKF6Xw=; b=ljypQiWmSVbFGUdgPbE7ELOy8YC5qnqWtXRTwrX723h6dzoBJkGz2500h0eYh1R39Y B7nY1X+ngHRNo0xs6PoOs/b14vKgVICelCXXZD+AKehjoiS7AfacZGjZqD2wgV6Vb8Mo nrZYMrI3F15kZvUAwgB06ZEY21UlC3e8VRDVxaAIRX3/GGchXDE/UEp+s6269ptZNZ8f oauOCPgO/OQp3y0kCrB8MlHnts7wCAwhaA3M/GCnYfSvVZjZbMbBzzxmJjPkI5biCRu7 hLTHlPHxYOXwh1lAFqWAyYUTCLaXazV9d6Vb9QL0uMYMJKWsJ4F5gQuIigkbcHnHYAaF 3QBw== 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=x4ns4T+1S1k8Yfl1+HirB82I68GDEC4NojYLSrKF6Xw=; b=olXDJLiaR9Mlx660vXGAwr0iBmIWq7xZYKWjkETVTBDQKzFGN/3K14dytRXzUAshHr 3evGbZW4FdoaLYCGT8SHC3QTWeIikfdCcxVIi1hru20K4klemXbl+XMfj5nQndBspONT JyEFUVKRxhiBfZd6EF2qQQa7+D2PMS/v82WKwlJIrT5OsF67XS+L9FMbsuWhyEGLW67w Y68hELBob9EOZQtCTESERXkzBTLzo6o/fTktC8zA1HCRId297eHlk3yCBufgfdm2N+p2 dck8Ne0u54Vrd3iDAfIZFPFNotdhPxZ16bVbf3/RaB4Qf8QxRVvJaPiYFI3sDtLmDvC+ bKrg== X-Gm-Message-State: APjAAAUtwp1kQkLIfrCmUURstclUZchyd6jBnbNU6AnMP6NHryeqjKTW M3QG+Asfvs/rPcqzTLI5tE4= X-Google-Smtp-Source: APXvYqykxCrSULkcnO/x04UMEYPX2uZ9AF8TxGlGwo+g0Cjy0bPFLa/3wqEBa0XE44qKKvwiE+q4lg== X-Received: by 2002:a63:eb56:: with SMTP id b22mr20836436pgk.355.1568016976588; Mon, 09 Sep 2019 01:16:16 -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 u65sm12686669pfu.104.2019.09.09.01.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:15 -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 v3 10/13] software node: rename is_array to is_inline Date: Mon, 9 Sep 2019 01:15:54 -0700 Message-Id: <20190909081557.93766-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 ration 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 | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 2dfeeab919d4..03643f55e5b5 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.raw; return &prop->value; @@ -204,7 +204,7 @@ static void property_entry_free_data(const struct property_entry *p) const void *pointer = property_get_pointer(p); size_t i, nval; - if (p->is_array) { + if (!p->is_inline) { if (p->type == DEV_PROP_STRING && p->pointer.str) { nval = p->length / sizeof(const char *); for (i = 0; i < nval; i++) @@ -247,7 +247,7 @@ static int property_entry_copy_data(struct property_entry *dst, const void *pointer = property_get_pointer(src); const void *new; - if (src->is_array) { + if (!src->is_inline) { if (!src->length) return -ENODATA; @@ -261,15 +261,16 @@ static int property_entry_copy_data(struct property_entry *dst, return -ENOMEM; } - dst->is_array = true; dst->pointer.raw = 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 793d05cbc3b2..5180e23348d2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -222,7 +222,8 @@ 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). @@ -230,7 +231,7 @@ static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, struct property_entry { const char *name; size_t length; - bool is_array; + bool is_inline; enum dev_prop_type type; union { union { @@ -264,7 +265,6 @@ struct property_entry { (struct property_entry) { \ .name = _name_, \ .length = ARRAY_SIZE(_val_) * PROPERTY_ENTRY_ELSIZE(_elem_), \ - .is_array = true, \ .type = DEV_PROP_##_Type_, \ .pointer._elem_ = _val_, \ } @@ -304,6 +304,7 @@ struct property_entry { .name = _name_, \ .length = PROPERTY_ENTRY_ELSIZE(_elem_), \ .type = DEV_PROP_##_Type_, \ + .is_inline = true, \ .value._elem_ = _val_, \ } From patchwork Mon Sep 9 08:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137407 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 18CD01395 for ; Mon, 9 Sep 2019 08:16:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D840E21A4C for ; Mon, 9 Sep 2019 08:16:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MG9+ry8L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389041AbfIIIQT (ORCPT ); Mon, 9 Sep 2019 04:16:19 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44050 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389034AbfIIIQS (ORCPT ); Mon, 9 Sep 2019 04:16:18 -0400 Received: by mail-pf1-f195.google.com with SMTP id q21so8652629pfn.11; Mon, 09 Sep 2019 01:16:18 -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=35xWhpJ4vTqiPEZAd1geSNcC3lLUdXhtiktpOpeubVg=; b=MG9+ry8LnfW9Y3XafCz3zWJMbYVNQEiPuYu6AdXywpBr02Lufe4yXXCVKoFHMLHDNT Cwr0NsqKItwHDM10nPYx/iXgHeXxldBI9AKgTF4Jy+VVM9bDWAxcmjnnPJ7Zpvn2RWF3 r/2UHbzrmH1BTkn3Im8+vFs2iLMFmCzli/XUxdL0hW4l8I7a2TmFCC/eMjw52ESE40yb BY3qUxG5raJIEy1txIQQ24rcOEoU6NtANUegGcgaBuByRB6+S1ywDibx1ob6u4zgTk2w Kef3e72KOkau1dKhvhPT57Rx1Rxm902pF2pSyjyyJ9wybhXbBwR8shQeXLrZD5/yF8jq JASA== 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=35xWhpJ4vTqiPEZAd1geSNcC3lLUdXhtiktpOpeubVg=; b=RMMOesSpyDntXsOaoHlIpZMiNFI90kikxmG2OUicx0+coByQxJ+mzstU/rWhzsKIs7 VNBFU7Ae2w62OuEvbu64Q3lKj1G4F5dH8PzdeB9O4CUlSt2zytXF4BinldMVciQSdY4t ShPHsLC8HHBf/Up/PVqDW+2bJz6FBAoZ44bKRhY4xTQrIWUE7U4yDD1lHkh1jBjlcbV3 Bf1gIaKTkJg+txsuAg/5UQXqrvcL3gpVxSLFEdMexnj+rzUwJGLDt08lVYfjC7NJ6Xqv 9l9j8z5Lz963x4LAu6auTO1nnI+O3KQKpJWLVWOX8DSzUlvIeE0bsy6mgZAXW6TZ78dB P+8Q== X-Gm-Message-State: APjAAAUSekIOkC0Cul8iFsBZBoGz5QiTE5eJDL4MqFxn7DQCFfHFlbtN UYhlaYOvOLFM+PoRvYrteY8= X-Google-Smtp-Source: APXvYqwtupkBTffWbYGpU9M0BA/lKlLKqd0/M+QnfYAxlR+QifpbGV80xoL2iTqBuVkLPJAR3LwOSw== X-Received: by 2002:a62:e708:: with SMTP id s8mr26245440pfh.114.1568016978102; Mon, 09 Sep 2019 01:16:18 -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 u65sm12686669pfu.104.2019.09.09.01.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:16 -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 v3 11/13] software node: implement reference properties Date: Mon, 9 Sep 2019 01:15:55 -0700 Message-Id: <20190909081557.93766-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 | 46 +++++++++++++++++++++++++++++++++------- include/linux/property.h | 46 ++++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 03643f55e5b5..4aaad0c7b1eb 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -262,6 +262,12 @@ static int property_entry_copy_data(struct property_entry *dst, } dst->pointer.raw = 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) @@ -447,21 +453,45 @@ 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_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_args = &prop->pointer.ref[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; @@ -480,7 +510,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 5180e23348d2..c9234fc43917 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. @@ -240,6 +255,7 @@ struct property_entry { const u32 *u32_data; const u64 *u64_data; const char * const *str; + const struct software_node_ref_args *ref; const void *raw; } pointer; union { @@ -279,6 +295,8 @@ struct property_entry { PROPERTY_ENTRY_ARRAY(_name_, u64_data, U64, _val_) #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ PROPERTY_ENTRY_ARRAY(_name_, str, STRING, _val_) +#define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \ + PROPERTY_ENTRY_ARRAY(_name_, ref, REF, _val_) #define PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_) \ (struct property_entry) { \ @@ -298,6 +316,8 @@ 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_LEN(_name_, ref, REF, _val_, _len) #define PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ @@ -324,6 +344,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.ref = &(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); @@ -387,20 +419,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 Mon Sep 9 08:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137403 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 4012416C1 for ; Mon, 9 Sep 2019 08:16:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08469206CD for ; Mon, 9 Sep 2019 08:16:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qigzDhNQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389065AbfIIIQV (ORCPT ); Mon, 9 Sep 2019 04:16:21 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43801 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389040AbfIIIQU (ORCPT ); Mon, 9 Sep 2019 04:16:20 -0400 Received: by mail-pg1-f196.google.com with SMTP id u72so7364273pgb.10; Mon, 09 Sep 2019 01:16:19 -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=s5lcI5ZT5uEtAOYeMR+NRyVAv3KOm634t5rLdZn9cuQ=; b=qigzDhNQZcpku6hm7hEXsLdHXT1JnLAMNU5YXdeG5NFyk1p/w53IZVCAku63n+C39B XJBsqXTsornza5NmUseAfdavAdIvbtT4fHxSArzwIVfYEomUuFWvP9YpwGSbqAq4qC// uLWFORbbG1/0Vjy5/XLJUHA1gGqHyREfPqPnqBe1lqt7VliTaKJ+FIsL0PGN9LLOOPDk W7S+kpHQ95/Sy/YyVu03BdxXYOrvx4gT2CqO+t02wZ7nhC7klKGFlAji+ckVInBptVGc rIyXFrt9CimpYJjsfa4Bg8iBX4JNbJXzCB5pv4l9H2TG6Sq5P5JHtSfkOWYUhU+4x6Pa PTmw== 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=s5lcI5ZT5uEtAOYeMR+NRyVAv3KOm634t5rLdZn9cuQ=; b=kDm0Oo+0UaT5xJ8GXC4BNlNhjOaMu2jvaDTZkSOJMJ+rrYOty2UAW8oZFwcIO4JTrM 9INGNRy3B0Nn9YNpWoUfqF1FdRWu9jFTw0OikN6INOdPDB2u/U4QSkHk20DGRdgACWbb ijm5OC1HbGrekZtwH42bJRAcJ7xWSt71nt9G4VdGWzlUkShSjY7QjU+I4X8DsgNxircO h2C0cAXslf2oor7bR++4WWolRvHev1R9KNsqcSsPvFdrkM64FQE+/XYX4IIM5TDOUz3o Jl4W8xCGKbs14dIjEy74VgX1hsf8CdxDy8w73aj3IHDG/ApdnIpQFPE0sn2vlaRICAC6 QryA== X-Gm-Message-State: APjAAAUaCkuFHyY8lfHwXOWw89Bud9M07nIlybRWm1tw8Q1YvTK9LQmr 5BftfTLAmeChUPAnfO6uBxE= X-Google-Smtp-Source: APXvYqx1wD9Vx1E7T/0OAPU57TO/5+PKImydhn67JmCWmT9shE/CMmb2nwX2jJ3qcydqZUaH3/KHHg== X-Received: by 2002:a63:fe52:: with SMTP id x18mr3660734pgj.344.1568016979143; Mon, 09 Sep 2019 01:16:19 -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 u65sm12686669pfu.104.2019.09.09.01.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:18 -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 v3 12/13] platform/x86: intel_cht_int33fe: use inline reference properties Date: Mon, 9 Sep 2019 01:15:56 -0700 Message-Id: <20190909081557.93766-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 Mon Sep 9 08:15:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11137405 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 4458A1395 for ; Mon, 9 Sep 2019 08:16:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D62A21A4C for ; Mon, 9 Sep 2019 08:16:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p5EqRRlJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389072AbfIIIQW (ORCPT ); Mon, 9 Sep 2019 04:16:22 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44053 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389064AbfIIIQV (ORCPT ); Mon, 9 Sep 2019 04:16:21 -0400 Received: by mail-pf1-f194.google.com with SMTP id q21so8652694pfn.11; Mon, 09 Sep 2019 01:16:20 -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=UtLtNTXEdU6C/yU6HS/q4vOOCRlfD3VhKvtyNVUaElQ=; b=p5EqRRlJRJIxCcqnSYcClS+b2Agv9cgjWAIYSC4ovPblZ+UMsneKfXyrhqaS6xZprR /vgFUmG91ralYNG2gP858XxwLl/5EEhyNXRn8ZgT0vGSWE92Gnc58fsVEki5VW5aYrpp tfo9tzxQIiPI4fnVDjv479YpDQBeGzzOqvdgFZdqN6PtK9HtXhwu9AGFlsp6mbHGBmyG GJztfKCgKX7VC/a2d7/FcVk4gff2tk5KTibK/IW/aBFRZNzKSPcrojdO4UsTEoLvx/Ue DQr66VhkRVqB56/o0Es4xfCGTEBvFmiz9pJ+fZ3oG5mk5t2N7smpjQPn0C4si+2LT2O6 U7hg== 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=UtLtNTXEdU6C/yU6HS/q4vOOCRlfD3VhKvtyNVUaElQ=; b=O1FJ6r/3HShsnAywUlWJ8NMARLuu7LPb0F4UrvXQcDjt9lxAsqpxwRNndF+q62BJJZ sNZYhPSMu6EzVQpT/xKxxLZ2Rz+/2PGvWhxmBFAfcUgRLkgT6TJLP3T2XXOpbivLBBv2 Uz0KDtLh0VQFBdy8b3p3N/eOTWHIT47iI6ORv8Au5DZOOEEkuPJZxQDgWtMJm2NmsrZF 796jgd8/wyVGZBXgO2ruP8Gpm2Do/ExQ2EOFslWNsDyngvjzrRcf4aoPVhTatNTpGTft h8W/qi7+1BAFAAaZoruxc84RX7jv4yoLVUd2itKtEKosv9eL4ok8PE1YzikudClmlvpG PIEw== X-Gm-Message-State: APjAAAXCEYOEI1BbVPtHdHdBXOimkO+8mmUa5JVB6zc7lvjqy4BGS+xa d8zniTxsjjxM46J1b84g6GU= X-Google-Smtp-Source: APXvYqxwW2cQ3r9xbGMuuXjFn4yVwKa0UiWh32a4KuHhTp5JI7Q/rVYNDtrTcg/ShjeZsKLE8JfOYw== X-Received: by 2002:a63:394:: with SMTP id 142mr20558333pgd.43.1568016980256; Mon, 09 Sep 2019 01:16:20 -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 u65sm12686669pfu.104.2019.09.09.01.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2019 01:16:19 -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 v3 13/13] software node: remove separate handling of references Date: Mon, 9 Sep 2019 01:15:57 -0700 Message-Id: <20190909081557.93766-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190909081557.93766-1-dmitry.torokhov@gmail.com> References: <20190909081557.93766-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 | 44 +++++++++++++++------------------------- include/linux/property.h | 14 ------------- 2 files changed, 16 insertions(+), 42 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 4aaad0c7b1eb..8085b39e23b4 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -452,8 +452,7 @@ 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_args; + const struct software_node_ref_args *ref; const struct property_entry *prop; struct fwnode_handle *refnode; int i; @@ -462,36 +461,25 @@ 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_args = &prop->pointer.ref[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 = &prop->pointer.ref[index]; - refnode = software_node_fwnode(ref_args->node); + refnode = software_node_fwnode(ref->node); if (!refnode) return -ENOENT; @@ -510,7 +498,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 c9234fc43917..67cd38936c1e 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -419,30 +419,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);