msm-4.14/drivers/of/resolver.c
Isaac J. Manjarres 44984fa144 Merge android-4.14.53 (57c2874) into msm-4.14
* remotes/origin/tmp-57c2874:
  Linux 4.14.53
  xhci: Fix use-after-free in xhci_free_virt_device
  dm thin: handle running out of data space vs concurrent discard
  dm zoned: avoid triggering reclaim from inside dmz_map()
  x86/efi: Fix efi_call_phys_epilog() with CONFIG_X86_5LEVEL=y
  block: Fix cloning of requests with a special payload
  block: Fix transfer when chunk sectors exceeds max
  slub: fix failure when we delete and create a slab cache
  ALSA: hda/realtek - Fix the problem of two front mics on more machines
  ALSA: hda/realtek - Add a quirk for FSC ESPRIMO U9210
  ALSA: hda/realtek - Fix pop noise on Lenovo P50 & co
  ALSA: timer: Fix UBSAN warning at SNDRV_TIMER_IOCTL_NEXT_DEVICE ioctl
  Input: elantech - fix V4 report decoding for module with middle key
  Input: elantech - enable middle button of touchpads on ThinkPad P52
  Input: elan_i2c_smbus - fix more potential stack buffer overflows
  Input: xpad - fix GPD Win 2 controller name
  udf: Detect incorrect directory size
  xen: Remove unnecessary BUG_ON from __unbind_from_irq()
  mm: fix devmem_is_allowed() for sub-page System RAM intersections
  mm/ksm.c: ignore STABLE_FLAG of rmap_item->address in rmap_walk_ksm()
  rbd: flush rbd_dev->watch_dwork after watch is unregistered
  pwm: lpss: platform: Save/restore the ctrl register over a suspend/resume
  Input: elan_i2c - add ELAN0618 (Lenovo v330 15IKB) ACPI ID
  ACPI / LPSS: Add missing prv_offset setting for byt/cht PWM devices
  video: uvesafb: Fix integer overflow in allocation
  NFSv4: Fix a typo in nfs41_sequence_process
  NFSv4: Revert commit 5f83d86cf531d ("NFSv4.x: Fix wraparound issues..")
  NFSv4: Fix possible 1-byte stack overflow in nfs_idmap_read_and_verify_message
  nfsd: restrict rd_maxcount to svc_max_payload in nfsd_encode_readdir
  media: dvb_frontend: fix locking issues at dvb_frontend_get_event()
  media: cx231xx: Add support for AverMedia DVD EZMaker 7
  media: v4l2-compat-ioctl32: prevent go past max size
  media: vsp1: Release buffers for each video node
  perf/x86/intel/uncore: Add event constraint for BDX PCU
  perf vendor events: Add Goldmont Plus V1 event file
  perf intel-pt: Fix packet decoding of CYC packets
  perf intel-pt: Fix "Unexpected indirect branch" error
  perf intel-pt: Fix MTC timing after overflow
  perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP
  perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING
  perf tools: Fix symbol and object code resolution for vdso32 and vdsox32
  arm: dts: mt7623: fix invalid memory node being generated
  mfd: intel-lpss: Fix Intel Cannon Lake LPSS I2C input clock
  mfd: intel-lpss: Program REMAP register in PIO mode
  backlight: tps65217_bl: Fix Device Tree node lookup
  backlight: max8925_bl: Fix Device Tree node lookup
  backlight: as3711_bl: Fix Device Tree node lookup
  UBIFS: Fix potential integer overflow in allocation
  ubi: fastmap: Correctly handle interrupted erasures in EBA
  ubi: fastmap: Cancel work upon detach
  rpmsg: smd: do not use mananged resources for endpoints and channels
  md: fix two problems with setting the "re-add" device state.
  rtc: sun6i: Fix bit_idx value for clk_register_gate
  clk: at91: PLL recalc_rate() now using cached MUL and DIV values
  linvdimm, pmem: Preserve read-only setting for pmem devices
  scsi: zfcp: fix missing REC trigger trace on enqueue without ERP thread
  scsi: zfcp: fix missing REC trigger trace for all objects in ERP_FAILED
  scsi: zfcp: fix missing REC trigger trace on terminate_rport_io for ERP_FAILED
  scsi: zfcp: fix missing REC trigger trace on terminate_rport_io early return
  scsi: zfcp: fix misleading REC trigger trace where erp_action setup failed
  scsi: zfcp: fix missing SCSI trace for retry of abort / scsi_eh TMF
  scsi: zfcp: fix missing SCSI trace for result of eh_host_reset_handler
  scsi: qla2xxx: Mask off Scope bits in retry delay
  scsi: qla2xxx: Fix setting lower transfer speed if GPSC fails
  scsi: hpsa: disable device during shutdown
  mm: fix __gup_device_huge vs unmap
  iio: sca3000: Fix an error handling path in 'sca3000_probe()'
  iio: adc: ad7791: remove sample freq sysfs attributes
  Btrfs: fix return value on rename exchange failure
  X.509: unpack RSA signatureValue field from BIT STRING
  irqchip/gic-v3-its: Don't bind LPI to unavailable NUMA node
  time: Make sure jiffies_to_msecs() preserves non-zero time periods
  MIPS: io: Add barrier after register read in inX()
  cpufreq: intel_pstate: Fix scaling max/min limits with Turbo 3.0
  pinctrl: devicetree: Fix pctldev pointer overwrite
  pinctrl: samsung: Correct EINTG banks order
  auxdisplay: fix broken menu
  PCI: pciehp: Clear Presence Detect and Data Link Layer Status Changed on resume
  PCI: Add ACS quirk for Intel 300 series
  PCI: Add ACS quirk for Intel 7th & 8th Gen mobile
  PCI: hv: Make sure the bus domain is really unique
  MIPS: BCM47XX: Enable 74K Core ExternalSync for PCIe erratum
  mtd: cfi_cmdset_0002: Avoid walking all chips when unlocking.
  mtd: cfi_cmdset_0002: Fix unlocking requests crossing a chip boudary
  mtd: cfi_cmdset_0002: fix SEGV unlocking multiple chips
  mtd: cfi_cmdset_0002: Use right chip in do_ppb_xxlock()
  mtd: cfi_cmdset_0002: Change write buffer to check correct value
  xprtrdma: Return -ENOBUFS when no pages are available
  RDMA/mlx4: Discard unknown SQP work requests
  IB/hfi1: Fix user context tail allocation for DMA_RTAIL
  IB/hfi1: Optimize kthread pointer locking when queuing CQ entries
  IB/hfi1: Reorder incorrect send context disable
  IB/hfi1: Fix fault injection init/exit issues
  IB/isert: fix T10-pi check mask setting
  IB/isert: Fix for lib/dma_debug check_sync warning
  IB/mlx5: Fetch soft WQE's on fatal error state
  IB/core: Make testing MR flags for writability a static inline function
  IB/mlx4: Mark user MR as writable if actual virtual memory is writable
  IB/{hfi1, qib}: Add handling of kernel restart
  IB/qib: Fix DMA api warning with debug kernel
  tpm: fix race condition in tpm_common_write()
  tpm: fix use after free in tpm2_load_context()
  of: platform: stop accessing invalid dev in of_platform_device_destroy
  of: unittest: for strings, account for trailing \0 in property length field
  of: overlay: validate offset from property fixups
  ARM64: dts: meson: disable sd-uhs modes on the libretech-cc
  arm64: mm: Ensure writes to swapper are ordered wrt subsequent cache maintenance
  arm64: kpti: Use early_param for kpti= command-line option
  arm64: Fix syscall restarting around signal suppressed by tracer
  ARM: dts: socfpga: Fix NAND controller node compatible for Arria10
  ARM: dts: socfpga: Fix NAND controller clock supply
  ARM: dts: socfpga: Fix NAND controller node compatible
  ARM: dts: Fix SPI node for Arria10
  ARM: 8764/1: kgdb: fix NUMREGBYTES so that gdb_regs[] is the correct size
  cxl: Disable prefault_mode in Radix mode
  soc: rockchip: power-domain: Fix wrong value when power up pd with writemask
  powerpc/fadump: Unregister fadump on kexec down path.
  cpuidle: powernv: Fix promotion from snooze if next state disabled
  powerpc/powernv/cpuidle: Init all present cpus for deep states
  powerpc/powernv: copy/paste - Mask SO bit in CR
  powerpc/powernv/ioda2: Remove redundant free of TCE pages
  powerpc/ptrace: Fix enforcement of DAWR constraints
  powerpc/perf: Fix memory allocation for core-imc based on num_possible_cpus()
  powerpc/ptrace: Fix setting 512B aligned breakpoints with PTRACE_SET_DEBUGREG
  powerpc/mm/hash: Add missing isync prior to kernel stack SLB switch
  fuse: fix control dir setup and teardown
  fuse: don't keep dead fuse_conn at fuse_fill_super().
  fuse: atomic_o_trunc should truncate pagecache
  fuse: fix congested state leak on aborted connections
  printk: fix possible reuse of va_list variable
  Bluetooth: hci_qca: Avoid missing rampatch failure with userspace fw loader
  ipmi:bt: Set the timeout before doing a capabilities check
  branch-check: fix long->int truncation when profiling branches
  mips: ftrace: fix static function graph tracing
  ftrace/selftest: Have the reset_trigger code be a bit more careful
  lib/vsprintf: Remove atomic-unsafe support for %pCr
  clk: renesas: cpg-mssr: Stop using printk format %pCr
  thermal: bcm2835: Stop using printk format %pCr
  ASoC: cirrus: i2s: Fix {TX|RX}LinCtrlData setup
  ASoC: cirrus: i2s: Fix LRCLK configuration
  ASoC: cs35l35: Add use_single_rw to regmap config
  ASoC: dapm: delete dapm_kcontrol_data paths list before freeing it
  1wire: family module autoload fails because of upper/lower case mismatch.
  usb: do not reset if a low-speed or full-speed device timed out
  PM / OPP: Update voltage in case freq == old_freq
  PM / core: Fix supplier device runtime PM usage counter imbalance
  PM / Domains: Fix error path during attach in genpd
  signal/xtensa: Consistenly use SIGBUS in do_unaligned_user
  serial: sh-sci: Use spin_{try}lock_irqsave instead of open coding version
  m68k/mac: Fix SWIM memory resource end address
  m68k/mm: Adjust VM area to be unmapped by gap size for __iounmap()
  x86: Call fixup_exception() before notify_die() in math_error()
  x86/mce: Do not overwrite MCi_STATUS in mce_no_way_out()
  x86/mce: Fix incorrect "Machine check from unknown source" message
  x86/mce: Check for alternate indication of machine check recovery on Skylake
  x86/mce: Improve error message when kernel cannot recover
  x86/xen: Add call of speculative_store_bypass_ht_init() to PV paths
  x86/spectre_v1: Disable compiler optimizations over array_index_mask_nospec()
  FROMLIST: trace: Reorder display of TGID to be after PID

Change-Id: I2e5135127f9d81a39dc77bc84fa50c76ec0b58af
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
2018-07-03 12:43:20 -07:00

349 lines
8.8 KiB
C

/*
* Functions for dealing with DT resolution
*
* Copyright (C) 2012 Pantelis Antoniou <panto@antoniou-consulting.com>
* Copyright (C) 2012 Texas Instruments Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
#define pr_fmt(fmt) "OF: resolver: " fmt
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include "of_private.h"
static phandle live_tree_max_phandle(void)
{
struct device_node *node;
phandle phandle;
unsigned long flags;
raw_spin_lock_irqsave(&devtree_lock, flags);
phandle = 0;
for_each_of_allnodes(node) {
if (node->phandle != OF_PHANDLE_ILLEGAL &&
node->phandle > phandle)
phandle = node->phandle;
}
raw_spin_unlock_irqrestore(&devtree_lock, flags);
return phandle;
}
static void adjust_overlay_phandles(struct device_node *overlay,
int phandle_delta)
{
struct device_node *child;
struct property *prop;
phandle phandle;
/* adjust node's phandle in node */
if (overlay->phandle != 0 && overlay->phandle != OF_PHANDLE_ILLEGAL)
overlay->phandle += phandle_delta;
/* copy adjusted phandle into *phandle properties */
for_each_property_of_node(overlay, prop) {
if (of_prop_cmp(prop->name, "phandle") &&
of_prop_cmp(prop->name, "linux,phandle"))
continue;
if (prop->length < 4)
continue;
phandle = be32_to_cpup(prop->value);
if (phandle == OF_PHANDLE_ILLEGAL)
continue;
*(__be32 *)prop->value = cpu_to_be32(overlay->phandle);
}
for_each_child_of_node(overlay, child)
adjust_overlay_phandles(child, phandle_delta);
}
static int update_usages_of_a_phandle_reference(struct device_node *overlay,
struct property *prop_fixup, phandle phandle)
{
struct device_node *refnode;
struct property *prop;
char *value, *cur, *end, *node_path, *prop_name, *s;
int offset, len;
int err = 0;
value = kmalloc(prop_fixup->length, GFP_KERNEL);
if (!value)
return -ENOMEM;
memcpy(value, prop_fixup->value, prop_fixup->length);
/* prop_fixup contains a list of tuples of path:property_name:offset */
end = value + prop_fixup->length;
for (cur = value; cur < end; cur += len + 1) {
len = strlen(cur);
node_path = cur;
s = strchr(cur, ':');
if (!s) {
err = -EINVAL;
goto err_fail;
}
*s++ = '\0';
prop_name = s;
s = strchr(s, ':');
if (!s) {
err = -EINVAL;
goto err_fail;
}
*s++ = '\0';
err = kstrtoint(s, 10, &offset);
if (err)
goto err_fail;
refnode = __of_find_node_by_full_path(of_node_get(overlay), node_path);
if (!refnode)
continue;
for_each_property_of_node(refnode, prop) {
if (!of_prop_cmp(prop->name, prop_name))
break;
}
of_node_put(refnode);
if (!prop) {
err = -ENOENT;
goto err_fail;
}
if (offset < 0 || offset + sizeof(__be32) > prop->length) {
err = -EINVAL;
goto err_fail;
}
*(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
}
err_fail:
kfree(value);
return err;
}
/* compare nodes taking into account that 'name' strips out the @ part */
static int node_name_cmp(const struct device_node *dn1,
const struct device_node *dn2)
{
const char *n1 = kbasename(dn1->full_name);
const char *n2 = kbasename(dn2->full_name);
return of_node_cmp(n1, n2);
}
/*
* Adjust the local phandle references by the given phandle delta.
*
* Subtree @local_fixups, which is overlay node __local_fixups__,
* mirrors the fragment node structure at the root of the overlay.
*
* For each property in the fragments that contains a phandle reference,
* @local_fixups has a property of the same name that contains a list
* of offsets of the phandle reference(s) within the respective property
* value(s). The values at these offsets will be fixed up.
*/
static int adjust_local_phandle_references(struct device_node *local_fixups,
struct device_node *overlay, int phandle_delta)
{
struct device_node *child, *overlay_child;
struct property *prop_fix, *prop;
int err, i, count;
unsigned int off;
phandle phandle;
if (!local_fixups)
return 0;
for_each_property_of_node(local_fixups, prop_fix) {
/* skip properties added automatically */
if (!of_prop_cmp(prop_fix->name, "name") ||
!of_prop_cmp(prop_fix->name, "phandle") ||
!of_prop_cmp(prop_fix->name, "linux,phandle"))
continue;
if ((prop_fix->length % 4) != 0 || prop_fix->length == 0)
return -EINVAL;
count = prop_fix->length / sizeof(__be32);
for_each_property_of_node(overlay, prop) {
if (!of_prop_cmp(prop->name, prop_fix->name))
break;
}
if (!prop)
return -EINVAL;
for (i = 0; i < count; i++) {
off = be32_to_cpu(((__be32 *)prop_fix->value)[i]);
if ((off + 4) > prop->length)
return -EINVAL;
phandle = be32_to_cpu(*(__be32 *)(prop->value + off));
phandle += phandle_delta;
*(__be32 *)(prop->value + off) = cpu_to_be32(phandle);
}
}
/*
* These nested loops recurse down two subtrees in parallel, where the
* node names in the two subtrees match.
*
* The roots of the subtrees are the overlay's __local_fixups__ node
* and the overlay's root node.
*/
for_each_child_of_node(local_fixups, child) {
for_each_child_of_node(overlay, overlay_child)
if (!node_name_cmp(child, overlay_child))
break;
if (!overlay_child)
return -EINVAL;
err = adjust_local_phandle_references(child, overlay_child,
phandle_delta);
if (err)
return err;
}
return 0;
}
/**
* of_resolve_phandles - Relocate and resolve overlay against live tree
*
* @overlay: Pointer to devicetree overlay to relocate and resolve
*
* Modify (relocate) values of local phandles in @overlay to a range that
* does not conflict with the live expanded devicetree. Update references
* to the local phandles in @overlay. Update (resolve) phandle references
* in @overlay that refer to the live expanded devicetree.
*
* Phandle values in the live tree are in the range of
* 1 .. live_tree_max_phandle(). The range of phandle values in the overlay
* also begin with at 1. Adjust the phandle values in the overlay to begin
* at live_tree_max_phandle() + 1. Update references to the phandles to
* the adjusted phandle values.
*
* The name of each property in the "__fixups__" node in the overlay matches
* the name of a symbol (a label) in the live tree. The values of each
* property in the "__fixups__" node is a list of the property values in the
* overlay that need to be updated to contain the phandle reference
* corresponding to that symbol in the live tree. Update the references in
* the overlay with the phandle values in the live tree.
*
* @overlay must be detached.
*
* Resolving and applying @overlay to the live expanded devicetree must be
* protected by a mechanism to ensure that multiple overlays are processed
* in a single threaded manner so that multiple overlays will not relocate
* phandles to overlapping ranges. The mechanism to enforce this is not
* yet implemented.
*
* Return: %0 on success or a negative error value on error.
*/
int of_resolve_phandles(struct device_node *overlay)
{
struct device_node *child, *local_fixups, *refnode;
struct device_node *tree_symbols, *overlay_fixups;
struct property *prop;
const char *refpath;
phandle phandle, phandle_delta;
int err;
tree_symbols = NULL;
if (!overlay) {
pr_err("null overlay\n");
err = -EINVAL;
goto out;
}
if (!of_node_check_flag(overlay, OF_DETACHED)) {
pr_err("overlay not detached\n");
err = -EINVAL;
goto out;
}
phandle_delta = live_tree_max_phandle() + 1;
adjust_overlay_phandles(overlay, phandle_delta);
for_each_child_of_node(overlay, local_fixups)
if (!of_node_cmp(local_fixups->name, "__local_fixups__"))
break;
err = adjust_local_phandle_references(local_fixups, overlay, phandle_delta);
if (err)
goto out;
overlay_fixups = NULL;
for_each_child_of_node(overlay, child) {
if (!of_node_cmp(child->name, "__fixups__"))
overlay_fixups = child;
}
if (!overlay_fixups) {
err = 0;
goto out;
}
tree_symbols = of_find_node_by_path("/__symbols__");
if (!tree_symbols) {
pr_err("no symbols in root of device tree.\n");
err = -EINVAL;
goto out;
}
for_each_property_of_node(overlay_fixups, prop) {
/* skip properties added automatically */
if (!of_prop_cmp(prop->name, "name"))
continue;
err = of_property_read_string(tree_symbols,
prop->name, &refpath);
if (err)
goto out;
refnode = of_find_node_by_path(refpath);
if (!refnode) {
err = -ENOENT;
goto out;
}
phandle = refnode->phandle;
of_node_put(refnode);
err = update_usages_of_a_phandle_reference(overlay, prop, phandle);
if (err)
break;
}
out:
if (err)
pr_err("overlay phandle fixup failed: %d\n", err);
of_node_put(tree_symbols);
return err;
}
EXPORT_SYMBOL_GPL(of_resolve_phandles);