1. 18 12月, 2019 2 次提交
  2. 01 12月, 2019 2 次提交
  3. 21 11月, 2019 2 次提交
  4. 10 11月, 2019 1 次提交
  5. 09 6月, 2019 2 次提交
    • F
      of: overlay: set node fields from properties when add new overlay node · b52ca352
      Frank Rowand 提交于
      commit f96278810150fc39085d1872e5b39ea06366d03e upstream.
      
      Overlay nodes added by add_changeset_node() do not have the node
      fields name, phandle, and type set.
      
      The node passed to __of_attach_node() when the add node changeset
      entry is processed does not contain any properties.  The node's
      properties are located in add property changeset entries that will
      be processed after the add node changeset is applied.
      
      Set the node's fields in the node contained in the add node
      changeset entry and do not set them to incorrect values in
      add_changeset_node().
      
      A visible symptom that is fixed by this patch is the names of nodes
      added by overlays that have an entry in /sys/bus/platform/drivers/*/
      will contain the unit-address but the node-name will be <NULL>,  for
      example, "fc4ab000.<NULL>".  After applying the patch the name, in
      this example, for node restart@fc4ab000 is "fc4ab000.restart".
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Phil Elwell <phil@raspberrypi.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b52ca352
    • F
      of: overlay: validate overlay properties #address-cells and #size-cells · 15151d00
      Frank Rowand 提交于
      commit 6f75118800acf77f8ad6afec61ca1b2349ade371 upstream.
      
      If overlay properties #address-cells or #size-cells are already in
      the live devicetree for any given node, then the values in the
      overlay must match the values in the live tree.
      
      If the properties are already in the live tree then there is no
      need to create a changeset entry to add them since they must
      have the same value.  This reduces the memory used by the
      changeset and eliminates a possible memory leak.
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      15151d00
  6. 07 2月, 2019 5 次提交
    • F
      of: overlay: do not duplicate properties from overlay for new nodes · 5b3109eb
      Frank Rowand 提交于
      commit 8814dc46bd9e347d4de55ec5bf8f16ea54470499 upstream.
      
      When allocating a new node, add_changeset_node() was duplicating the
      properties from the respective node in the overlay instead of
      allocating a node with no properties.
      
      When this patch is applied the errors reported by the devictree
      unittest from patch "of: overlay: add tests to validate kfrees from
      overlay removal" will no longer occur.  These error messages are of
      the form:
      
         "OF: ERROR: ..."
      
      and the unittest results will change from:
      
         ### dt-test ### end of unittest - 203 passed, 7 failed
      
      to
      
         ### dt-test ### end of unittest - 210 passed, 0 failed
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5b3109eb
    • F
      of: overlay: use prop add changeset entry for property in new nodes · 7251e4b8
      Frank Rowand 提交于
      commit 6b4955ba7bc05e40c8c41071cc121bc26ca65277 upstream.
      
      The changeset entry 'update property' was used for new properties in
      an overlay instead of 'add property'.
      
      The decision of whether to use 'update property' was based on whether
      the property already exists in the subtree where the node is being
      spliced into.  At the top level of creating a changeset describing the
      overlay, the target node is in the live devicetree, so checking whether
      the property exists in the target node returns the correct result.
      As soon as the changeset creation algorithm recurses into a new node,
      the target is no longer in the live devicetree, but is instead in the
      detached overlay tree, thus all properties are incorrectly found to
      already exist in the target.
      
      This fix will expose another devicetree bug that will be fixed
      in the following patch in the series.
      
      When this patch is applied the errors reported by the devictree
      unittest will change, and the unittest results will change from:
      
         ### dt-test ### end of unittest - 210 passed, 0 failed
      
      to
      
         ### dt-test ### end of unittest - 203 passed, 7 failed
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7251e4b8
    • F
      of: overlay: add missing of_node_get() in __of_attach_node_sysfs · 9af27fab
      Frank Rowand 提交于
      commit 5b2c2f5a0ea3a43e0dee78059e34c7cb54136dcc upstream.
      
      There is a matching of_node_put() in __of_detach_node_sysfs()
      
      Remove misleading comment from function header comment for
      of_detach_node().
      
      This patch may result in memory leaks from code that directly calls
      the dynamic node add and delete functions directly instead of
      using changesets.
      
      This commit should result in powerpc systems that dynamically
      allocate a node, then later deallocate the node to have a
      memory leak when the node is deallocated.
      
      The next commit will fix the leak.
      Tested-by: NAlan Tull <atull@kernel.org>
      Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9af27fab
    • F
      of: overlay: add tests to validate kfrees from overlay removal · 5006496f
      Frank Rowand 提交于
      commit 144552c786925314c1e7cb8f91a71dae1aca8798 upstream.
      
      Add checks:
        - attempted kfree due to refcount reaching zero before overlay
          is removed
        - properties linked to an overlay node when the node is removed
        - node refcount > one during node removal in a changeset destroy,
          if the node was created by the changeset
      
      After applying this patch, several validation warnings will be
      reported from the devicetree unittest during boot due to
      pre-existing devicetree bugs. The warnings will be similar to:
      
        OF: ERROR: of_node_release(), unexpected properties in /testcase-data/overlay-node/test-bus/test-unittest11
        OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node /testcase-data-2/substation@100/
        hvac-medium-2
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5006496f
    • R
      of: Convert to using %pOFn instead of device_node.name · 3edc2fac
      Rob Herring 提交于
      commit a613b26a50136ae90ab13943afe90bcbd34adb44 upstream.
      
      In preparation to remove the node name pointer from struct device_node,
      convert printf users to use the %pOFn format specifier.
      Reviewed-by: NFrank Rowand <frank.rowand@sony.com>
      Cc: Andrew Lunn <andrew@lunn.ch>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: netdev@vger.kernel.org
      Signed-off-by: NRob Herring <robh@kernel.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3edc2fac
  7. 26 1月, 2019 1 次提交
    • F
      of: overlay: add missing of_node_put() after add new node to changeset · b6d75422
      Frank Rowand 提交于
      [ Upstream commit 7c528e457d53c75107d5aa56892316d265c778de ]
      
      The refcount of a newly added overlay node decrements to one
      (instead of zero) when the overlay changeset is destroyed.  This
      change will cause the final decrement be to zero.
      
      After applying this patch, new validation warnings will be
      reported from the devicetree unittest during boot due to
      a pre-existing devicetree bug.  The warnings will be similar to:
      
        OF: ERROR: memory leak before free overlay changeset,  /testcase-data/overlay-node/test-bus/test-unittest4
      
      This pre-existing devicetree bug will also trigger a WARN_ONCE() from
      refcount_sub_and_test_checked() when an overlay changeset is
      destroyed without having first been applied.  This scenario occurs
      when an error in the overlay is detected during the overlay changeset
      creation:
      
        WARNING: CPU: 0 PID: 1 at lib/refcount.c:187 refcount_sub_and_test_checked+0xa8/0xbc
        refcount_t: underflow; use-after-free.
      
        (unwind_backtrace) from (show_stack+0x10/0x14)
        (show_stack) from (dump_stack+0x6c/0x8c)
        (dump_stack) from (__warn+0xdc/0x104)
        (__warn) from (warn_slowpath_fmt+0x44/0x6c)
        (warn_slowpath_fmt) from (refcount_sub_and_test_checked+0xa8/0xbc)
        (refcount_sub_and_test_checked) from (kobject_put+0x24/0x208)
        (kobject_put) from (of_changeset_destroy+0x2c/0xb4)
        (of_changeset_destroy) from (free_overlay_changeset+0x1c/0x9c)
        (free_overlay_changeset) from (of_overlay_remove+0x284/0x2cc)
        (of_overlay_remove) from (of_unittest_apply_revert_overlay_check.constprop.4+0xf8/0x1e8)
        (of_unittest_apply_revert_overlay_check.constprop.4) from (of_unittest_overlay+0x960/0xed8)
        (of_unittest_overlay) from (of_unittest+0x1cc4/0x2138)
        (of_unittest) from (do_one_initcall+0x4c/0x28c)
        (do_one_initcall) from (kernel_init_freeable+0x29c/0x378)
        (kernel_init_freeable) from (kernel_init+0x8/0x110)
        (kernel_init) from (ret_from_fork+0x14/0x2c)
      Tested-by: NAlan Tull <atull@kernel.org>
      Signed-off-by: NFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b6d75422
  8. 23 1月, 2019 1 次提交
  9. 13 1月, 2019 2 次提交
  10. 27 11月, 2018 1 次提交
  11. 21 11月, 2018 1 次提交
    • J
      of, numa: Validate some distance map rules · 3cbdaf13
      John Garry 提交于
      commit 89c38422 upstream.
      
      Currently the NUMA distance map parsing does not validate the distance
      table for the distance-matrix rules 1-2 in [1].
      
      However the arch NUMA code may enforce some of these rules, but not all.
      Such is the case for the arm64 port, which does not enforce the rule that
      the distance between separates nodes cannot equal LOCAL_DISTANCE.
      
      The patch adds the following rules validation:
      - distance of node to self equals LOCAL_DISTANCE
      - distance of separate nodes > LOCAL_DISTANCE
      
      This change avoids a yet-unresolved crash reported in [2].
      
      A note on dealing with symmetrical distances between nodes:
      
      Validating symmetrical distances between nodes is difficult. If it were
      mandated in the bindings that every distance must be recorded in the
      table, then it would be easy. However, it isn't.
      
      In addition to this, it is also possible to record [b, a] distance only
      (and not [a, b]). So, when processing the table for [b, a], we cannot
      assert that current distance of [a, b] != [b, a] as invalid, as [a, b]
      distance may not be present in the table and current distance would be
      default at REMOTE_DISTANCE.
      
      As such, we maintain the policy that we overwrite distance [a, b] = [b, a]
      for b > a. This policy is different to kernel ACPI SLIT validation, which
      allows non-symmetrical distances (ACPI spec SLIT rules allow it). However,
      the distance debug message is dropped as it may be misleading (for a distance
      which is later overwritten).
      
      Some final notes on semantics:
      
      - It is implied that it is the responsibility of the arch NUMA code to
        reset the NUMA distance map for an error in distance map parsing.
      
      - It is the responsibility of the FW NUMA topology parsing (whether OF or
        ACPI) to enforce NUMA distance rules, and not arch NUMA code.
      
      [1] Documents/devicetree/bindings/numa.txt
      [2] https://www.spinics.net/lists/arm-kernel/msg683304.html
      
      Cc: stable@vger.kernel.org # 4.7
      Signed-off-by: NJohn Garry <john.garry@huawei.com>
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3cbdaf13
  12. 14 11月, 2018 1 次提交
  13. 10 10月, 2018 1 次提交
    • G
      of: unittest: Disable interrupt node tests for old world MAC systems · 88948914
      Guenter Roeck 提交于
      On systems with OF_IMAP_OLDWORLD_MAC set in of_irq_workarounds, the
      devicetree interrupt parsing code is different, causing unit tests of
      devicetree interrupt nodes to fail. Due to a bug in unittest code, which
      tries to dereference an uninitialized pointer, this results in a crash.
      
      OF: /testcase-data/phandle-tests/consumer-a: arguments longer than property
      Unable to handle kernel paging request for data at address 0x00bc616e
      Faulting instruction address: 0xc08e9468
      Oops: Kernel access of bad area, sig: 11 [#1]
      BE PREEMPT PowerMac
      Modules linked in:
      CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.72-rc1-yocto-standard+ #1
      task: cf8e0000 task.stack: cf8da000
      NIP:  c08e9468 LR: c08ea5bc CTR: c08ea5ac
      REGS: cf8dbb50 TRAP: 0300   Not tainted  (4.14.72-rc1-yocto-standard+)
      MSR:  00001032 <ME,IR,DR,RI>  CR: 82004044  XER: 00000000
      DAR: 00bc616e DSISR: 40000000
      GPR00: c08ea5bc cf8dbc00 cf8e0000 c13ca517 c13ca517 c13ca8a0 00000066 00000002
      GPR08: 00000063 00bc614e c0b05865 000affff 82004048 00000000 c00047f0 00000000
      GPR16: c0a80000 c0a9cc34 c13ca517 c0ad1134 05ffffff 000affff c0b05860 c0abeef8
      GPR24: cecec278 cecec278 c0a8c4d0 c0a885e0 c13ca8a0 05ffffff c13ca8a0 c13ca517
      
      NIP [c08e9468] device_node_gen_full_name+0x30/0x15c
      LR [c08ea5bc] device_node_string+0x190/0x3c8
      Call Trace:
      [cf8dbc00] [c007f670] trace_hardirqs_on_caller+0x118/0x1fc (unreliable)
      [cf8dbc40] [c08ea5bc] device_node_string+0x190/0x3c8
      [cf8dbcb0] [c08eb794] pointer+0x25c/0x4d0
      [cf8dbd00] [c08ebcbc] vsnprintf+0x2b4/0x5ec
      [cf8dbd60] [c08ec00c] vscnprintf+0x18/0x48
      [cf8dbd70] [c008e268] vprintk_store+0x4c/0x22c
      [cf8dbda0] [c008ecac] vprintk_emit+0x94/0x130
      [cf8dbdd0] [c008ff54] printk+0x5c/0x6c
      [cf8dbe10] [c0b8ddd4] of_unittest+0x2220/0x26f8
      [cf8dbea0] [c0004434] do_one_initcall+0x4c/0x184
      [cf8dbf00] [c0b4534c] kernel_init_freeable+0x13c/0x1d8
      [cf8dbf30] [c0004814] kernel_init+0x24/0x118
      [cf8dbf40] [c0013398] ret_from_kernel_thread+0x5c/0x64
      
      The problem was observed when running a qemu test for the g3beige machine
      with devicetree unittests enabled.
      
      Disable interrupt node tests on affected systems to avoid both false
      unittest failures and the crash.
      
      With this patch in place, unittest on the affected system passes with
      the following message.
      
      	dt-test ### end of unittest - 144 passed, 0 failed
      
      Fixes: 53a42093 ("of: Add device tree selftests")
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: NFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: NRob Herring <robh@kernel.org>
      88948914
  14. 12 9月, 2018 1 次提交
  15. 02 9月, 2018 1 次提交
    • L
      of/platform: initialise AMBA default DMA masks · 8c89ef7b
      Linus Walleij 提交于
      This addresses a v4.19-rc1 regression in the PL111 DRM driver in
      drivers/gpu/pl111/*
      
      The driver uses the CMA KMS helpers and will thus at some point call
      down to dma_alloc_attrs() to allocate a chunk of contigous DMA memory
      for the framebuffer.
      
      It appears that in v4.18, it was OK that this (and other DMA mastering
      AMBA devices) left dev->coherent_dma_mask blank (zero).
      
      In v4.19-rc1 the WARN_ON_ONCE(dev && !dev->coherent_dma_mask) in
      dma_alloc_attrs() in include/linux/dma-mapping.h is triggered.  The
      allocation later fails when get_coherent_dma_mask() is called from
      __dma_alloc() and __dma_alloc() returns NULL:
      
      drm-clcd-pl111 dev:20: coherent DMA mask is unset
      drm-clcd-pl111 dev:20: [drm:drm_fb_helper_fbdev_setup] *ERROR*
       	       	        Failed to set fbdev configuration
      
      It turns out that in commit 4d8bde88 ("OF: Don't set default
      coherent DMA mask") the OF core stops setting the default DMA mask on
      new devices, especially those lines of the patch:
      
      - if (!dev->coherent_dma_mask)
      -               dev->coherent_dma_mask = DMA_BIT_MASK(32);
      
      Robin Murphy solved a similar problem in a5516219 ("of/platform:
      Initialise default DMA masks") by simply assigning dev.coherent_dma_mask
      and the dev.dma_mask to point to the same when creating devices from the
      device tree, and introducing the same code into the code path creating
      AMBA/PrimeCell devices solved my problem, graphics now come up.
      
      The code simply assumes that the device can access all of the system
      memory by setting the coherent DMA mask to 0xffffffff when creating a
      device from the device tree, which is crude, but seems to be what kernel
      v4.18 assumed.
      
      The AMBA PrimeCells do not differ between coherent and streaming DMA so
      we can just assign the same to any DMA mask.
      
      Possibly drivers should augment their coherent DMA mask in accordance
      with "dma-ranges" from the device tree if more finegranular masking is
      needed.
      Reported-by: NRussell King <linux@armlinux.org.uk>
      Fixes: 4d8bde88 ("OF: Don't set default coherent DMA mask")
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      8c89ef7b
  16. 31 8月, 2018 1 次提交
  17. 29 8月, 2018 1 次提交
    • J
      of: add helper to lookup compatible child node · 36156f92
      Johan Hovold 提交于
      Add of_get_compatible_child() helper that can be used to lookup
      compatible child nodes.
      
      Several drivers currently use of_find_compatible_node() to lookup child
      nodes while failing to notice that the of_find_ functions search the
      entire tree depth-first (from a given start node) and therefore can
      match unrelated nodes. The fact that these functions also drop a
      reference to the node they start searching from (e.g. the parent node)
      is typically also overlooked, something which can lead to use-after-free
      bugs.
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NRob Herring <robh@kernel.org>
      36156f92
  18. 08 8月, 2018 1 次提交
    • M
      of/fdt: Remove PPC32 longtrail hack in memory scan · da653130
      Michael Ellerman 提交于
      When the OF code was originally made common by Grant in commit
      51975db0 ("of/flattree: merge early_init_dt_scan_memory() common
      code") (Feb 2010), the common code inherited a hack to handle
      PPC "longtrail" machines, which had a "memory@0" node with no
      device_type.
      
      That check was then made to only apply to PPC32 in b44aa25d ("of:
      Handle memory@0 node on PPC32 only") (May 2014).
      
      But according to Paul Mackerras the "longtrail" machines are long
      dead, if they were ever seen in the wild at all. If someone does still
      have one, we can handle this firmware wart in powerpc platform code.
      
      So remove the hack once and for all.
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: NRob Herring <robh@kernel.org>
      da653130
  19. 28 7月, 2018 3 次提交
  20. 16 7月, 2018 1 次提交
  21. 14 7月, 2018 1 次提交
    • L
      of: mdio: Support fixed links in of_phy_get_and_connect() · 6eb9c9da
      Linus Walleij 提交于
      By a simple extension of of_phy_get_and_connect() drivers
      that have a fixed link on e.g. RGMII can support also
      fixed links, so in addition to:
      
      ethernet-port {
      	phy-mode = "rgmii";
      	phy-handle = <&foo>;
      };
      
      This setup with a fixed-link node and no phy-handle will
      now also work just fine:
      
      ethernet-port {
      	phy-mode = "rgmii";
      	fixed-link {
      		speed = <1000>;
      		full-duplex;
      		pause;
      	};
      };
      
      This is very helpful for connecting random ethernet ports
      to e.g. DSA switches that typically reside on fixed links.
      
      The phy-mode is still there as the fixes link in this case
      is still an RGMII link.
      
      Tested on the Cortina Gemini driver with the Vitesse DSA
      router chip on a fixed 1Gbit link.
      Suggested-by: NAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      Reviewed-by: NAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      6eb9c9da
  22. 10 7月, 2018 1 次提交
  23. 13 6月, 2018 1 次提交
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
  24. 04 6月, 2018 1 次提交
    • S
      of: platform: stop accessing invalid dev in of_platform_device_destroy · 522811e9
      Srinivas Kandagatla 提交于
      Immediately after the platform_device_unregister() the device will be
      cleaned up. Accessing the freed pointer immediately after that will
      crash the system.
      
      Found this bug when kernel is built with CONFIG_PAGE_POISONING and testing
      loading/unloading audio drivers in a loop on Qcom platforms.
      
      Fix this by moving of_node_clear_flag() just before the unregister calls.
      
      Below is the crash trace:
      
      Unable to handle kernel paging request at virtual address 6b6b6b6b6b6c03
      Mem abort info:
        ESR = 0x96000021
        Exception class = DABT (current EL), IL = 32 bits
        SET = 0, FnV = 0
        EA = 0, S1PTW = 0
      Data abort info:
        ISV = 0, ISS = 0x00000021
        CM = 0, WnR = 0
      [006b6b6b6b6b6c03] address between user and kernel address ranges
      Internal error: Oops: 96000021 [#1] PREEMPT SMP
      Modules linked in:
      CPU: 2 PID: 1784 Comm: sh Tainted: G        W         4.17.0-rc7-02230-ge3a63a7ef641-dirty #204
      Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT)
      pstate: 80000005 (Nzcv daif -PAN -UAO)
      pc : clear_bit+0x18/0x2c
      lr : of_platform_device_destroy+0x64/0xb8
      sp : ffff00000c9c3930
      x29: ffff00000c9c3930 x28: ffff80003d39b200
      x27: ffff000008bb1000 x26: 0000000000000040
      x25: 0000000000000124 x24: ffff80003a9a3080
      x23: 0000000000000060 x22: ffff00000939f518
      x21: ffff80003aa79e98 x20: ffff80003aa3dae0
      x19: ffff80003aa3c890 x18: ffff800009feb794
      x17: 0000000000000000 x16: 0000000000000000
      x15: ffff800009feb790 x14: 0000000000000000
      x13: ffff80003a058778 x12: ffff80003a058728
      x11: ffff80003a058750 x10: 0000000000000000
      x9 : 0000000000000006 x8 : ffff80003a825988
      x7 : bbbbbbbbbbbbbbbb x6 : 0000000000000001
      x5 : 0000000000000000 x4 : 0000000000000001
      x3 : 0000000000000008 x2 : 0000000000000001
      x1 : 6b6b6b6b6b6b6c03 x0 : 0000000000000000
      Process sh (pid: 1784, stack limit = 0x        (ptrval))
      Call trace:
       clear_bit+0x18/0x2c
       q6afe_remove+0x20/0x38
       apr_device_remove+0x30/0x70
       device_release_driver_internal+0x170/0x208
       device_release_driver+0x14/0x20
       bus_remove_device+0xcc/0x150
       device_del+0x10c/0x310
       device_unregister+0x1c/0x70
       apr_remove_device+0xc/0x18
       device_for_each_child+0x50/0x80
       apr_remove+0x18/0x20
       rpmsg_dev_remove+0x38/0x68
       device_release_driver_internal+0x170/0x208
       device_release_driver+0x14/0x20
       bus_remove_device+0xcc/0x150
       device_del+0x10c/0x310
       device_unregister+0x1c/0x70
       qcom_smd_remove_device+0xc/0x18
       device_for_each_child+0x50/0x80
       qcom_smd_unregister_edge+0x3c/0x70
       smd_subdev_remove+0x18/0x28
       rproc_stop+0x48/0xd8
       rproc_shutdown+0x60/0xe8
       state_store+0xbc/0xf8
       dev_attr_store+0x18/0x28
       sysfs_kf_write+0x3c/0x50
       kernfs_fop_write+0x118/0x1e0
       __vfs_write+0x18/0x110
       vfs_write+0xa4/0x1a8
       ksys_write+0x48/0xb0
       sys_write+0xc/0x18
       el0_svc_naked+0x30/0x34
      Code: d2800022 8b400c21 f9800031 9ac32043 (c85f7c22)
      ---[ end trace 32020935775616a2 ]---
      Signed-off-by: NSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: NRob Herring <robh@kernel.org>
      522811e9
  25. 26 5月, 2018 1 次提交
  26. 24 5月, 2018 1 次提交
  27. 23 5月, 2018 1 次提交
  28. 17 5月, 2018 1 次提交
  29. 03 5月, 2018 1 次提交