Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933872AbcJFSg7 (ORCPT ); Thu, 6 Oct 2016 14:36:59 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47760 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932368AbcJFSgo (ORCPT ); Thu, 6 Oct 2016 14:36:44 -0400 From: Reza Arbab To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Rob Herring , Frank Rowand , Andrew Morton Cc: Bharata B Rao , Nathan Fontenot , Stewart Smith , Alistair Popple , Balbir Singh , "Aneesh Kumar K.V" , Tang Chen , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v4 1/5] drivers/of: introduce of_fdt_device_is_available() Date: Thu, 6 Oct 2016 13:36:31 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1475778995-1420-1-git-send-email-arbab@linux.vnet.ibm.com> References: <1475778995-1420-1-git-send-email-arbab@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16100618-8235-0000-0000-00000958E899 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005864; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000186; SDB=6.00765136; UDB=6.00365562; IPR=6.00540998; BA=6.00004791; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012897; XFM=3.00000011; UTC=2016-10-06 18:36:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16100618-8236-0000-0000-0000356FD893 Message-Id: <1475778995-1420-2-git-send-email-arbab@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-06_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610060324 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3119 Lines: 95 In __fdt_scan_reserved_mem(), the availability of a node is determined by testing its "status" property. Move this check into its own function, borrowing logic from the unflattened version, of_device_is_available(). Another caller will be added in a subsequent patch. Signed-off-by: Reza Arbab Acked-by: Rob Herring --- drivers/of/fdt.c | 26 +++++++++++++++++++++++--- include/linux/of_fdt.h | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 085c638..b138efb 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -151,6 +151,23 @@ int of_fdt_match(const void *blob, unsigned long node, return score; } +bool of_fdt_device_is_available(const void *blob, unsigned long node) +{ + const char *status; + int statlen; + + status = fdt_getprop(blob, node, "status", &statlen); + if (!status) + return true; + + if (statlen) { + if (!strcmp(status, "okay") || !strcmp(status, "ok")) + return true; + } + + return false; +} + static void *unflatten_dt_alloc(void **mem, unsigned long size, unsigned long align) { @@ -647,7 +664,6 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname, int depth, void *data) { static int found; - const char *status; int err; if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) { @@ -667,8 +683,7 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname, return 1; } - status = of_get_flat_dt_prop(node, "status", NULL); - if (status && strcmp(status, "okay") != 0 && strcmp(status, "ok") != 0) + if (!of_flat_dt_device_is_available(node)) return 0; err = __reserved_mem_reserve_reg(node, uname); @@ -809,6 +824,11 @@ int __init of_flat_dt_match(unsigned long node, const char *const *compat) return of_fdt_match(initial_boot_params, node, compat); } +bool __init of_flat_dt_device_is_available(unsigned long node) +{ + return of_fdt_device_is_available(initial_boot_params, node); +} + struct fdt_scan_status { const char *name; int namelen; diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 26c3302..4ff8c8e 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,6 +37,7 @@ extern bool of_fdt_is_big_endian(const void *blob, unsigned long node); extern int of_fdt_match(const void *blob, unsigned long node, const char *const *compat); +extern bool of_fdt_device_is_available(const void *blob, unsigned long node); extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node *dad, struct device_node **mynodes); @@ -59,6 +60,7 @@ extern const void *of_get_flat_dt_prop(unsigned long node, const char *name, int *size); extern int of_flat_dt_is_compatible(unsigned long node, const char *name); extern int of_flat_dt_match(unsigned long node, const char *const *matches); +extern bool of_flat_dt_device_is_available(unsigned long node); extern unsigned long of_get_flat_dt_root(void); extern int of_get_flat_dt_size(void); -- 1.8.3.1