1. 13 6月, 2018 1 次提交
    • K
      treewide: devm_kzalloc() -> devm_kcalloc() · a86854d0
      Kees Cook 提交于
      The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
      This patch replaces cases of:
      
              devm_kzalloc(handle, a * b, gfp)
      
      with:
              devm_kcalloc(handle, a * b, gfp)
      
      as well as handling cases of:
      
              devm_kzalloc(handle, a * b * c, gfp)
      
      with:
      
              devm_kzalloc(handle, array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              devm_kcalloc(handle, array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              devm_kzalloc(handle, 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.
      
      Some manual whitespace fixes were needed in this patch, as Coccinelle
      really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      expression HANDLE;
      type TYPE;
      expression THING, E;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression HANDLE;
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      expression HANDLE;
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      expression HANDLE;
      identifier SIZE, COUNT;
      @@
      
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression HANDLE;
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression HANDLE;
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      expression HANDLE;
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	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 HANDLE;
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	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 HANDLE;
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
      |
        devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2, ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      a86854d0
  2. 03 1月, 2018 3 次提交
    • E
      hwmon: (pmbus) Export pmbus device debugfs directory entry · eb6489b6
      Edward A. James 提交于
      Pmbus client drivers, if they want to use debugfs, should use the same
      root directory as the pmbus debugfs entries are using. Therefore, export
      the device dentry for the pmbus client.
      Signed-off-by: NEdward A. James <eajames@us.ibm.com>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      eb6489b6
    • A
      hwmon: (pmbus) Add virtual page config bit · 464df6fa
      Andrew Jeffery 提交于
      Some circumstances call for virtual pages, to expose multiple values
      packed into an extended PMBus register in a manner non-compliant with
      the PMBus standard. An example of this is the Maxim MAX31785 controller,
      which extends the READ_FAN_SPEED_1 PMBus register from two to four bytes
      to support tach readings for both rotors of a dual rotor fan. This extended
      register contains two word-sized values, one reporting the rate of the
      fastest rotor, the other the rate of the slowest. The concept of virtual
      pages aids this situation by mapping the page number onto the value to be
      selected from the vectored result.
      
      We should not try to set virtual pages on the device as such a page
      explicitly doesn't exist; add a flag so we can avoid doing so.
      Signed-off-by: NAndrew Jeffery <andrew@aj.id.au>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      464df6fa
    • A
      hwmon: (pmbus) Add fan control support · d206636e
      Andrew Jeffery 提交于
      Expose fanX_target, pwmX and pwmX_enable hwmon sysfs attributes.
      
      Fans in a PMBus device are driven by the configuration of two registers,
      FAN_CONFIG_x_y and FAN_COMMAND_x: FAN_CONFIG_x_y dictates how the fan
      and the tacho operate (if installed), while FAN_COMMAND_x sets the
      desired fan rate. The unit of FAN_COMMAND_x is dependent on the
      operational fan mode, RPM or PWM percent duty, as determined by the
      corresponding configuration in FAN_CONFIG_x_y.
      
      The mapping of fanX_target, pwmX and pwmX_enable onto FAN_CONFIG_x_y and
      FAN_COMMAND_x is implemented with the addition of virtual registers to
      facilitate the necessary side-effects of each access:
      
      1. PMBUS_VIRT_FAN_TARGET_x
      2. PMBUS_VIRT_PWM_x
      3. PMBUS_VIRT_PWM_ENABLE_x
      
      Some complexity arises with the fanX_target and pwmX attributes both mapping
      onto FAN_COMMAND_x: There is no general mapping between PWM percent duty and
      RPM, so we can't display values in either attribute in terms of the other
      (which in my mind is the intuitive, if impossible, behaviour). This problem
      also affects the pwmX_enable attribute which allows userspace to switch between
      full speed, manual PWM and a number of automatic control modes, possibly
      including a switch to RPM behaviour (e.g. automatically adjusting PWM duty to
      reach a RPM target, the behaviour of fanX_target).
      
      The next most intuitive behaviour is for fanX_target and pwmX to simply be
      independent, to retain their most recently set value even if that value is not
      active on the hardware (due to switching to the alternative control mode). This
      property of retaining the value independent of the hardware state has useful
      results for both userspace and the kernel: Userspace always sees a sensible
      value in the attribute (the last thing it was set to, as opposed to 0 or
      receiving an error on read), and the kernel can use the attributes as a value
      cache. This latter point eases the implementation of pwmX_enable, which can
      look up the associated pmbus_sensor object, take its cached value and apply it
      to hardware on changing control mode. This ensures we will not arbitrarily set
      a PWM value as an RPM value or vice versa, and we can assume that the RPM or
      PWM value set was sensible at least at some point in the past.
      
      Finally, the DIRECT mode coefficients of some controllers is different between
      RPM and PWM percent duty control modes, so PSC_PWM is introduced to capture the
      necessary coefficients. As pmbus core had no PWM support previously PSC_FAN
      continues to be used to capture the RPM DIRECT coefficients, but in order to
      avoid falsely applying RPM scaling to PWM values I have introduced the
      PMBUS_HAVE_PWM12 and PMB_BUS_HAVE_PWM34 feature bits. These feature bits allow
      drivers to explicitly declare PWM support in order to have the attributes
      exposed.
      Signed-off-by: NAndrew Jeffery <andrew@aj.id.au>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      d206636e
  3. 28 11月, 2017 1 次提交
  4. 30 10月, 2017 1 次提交
    • E
      hwmon: (pmbus/core) Prevent unintentional setting of page to 0xFF · 6dcf2fb5
      Edward A. James 提交于
      The pmbus core may call read/write word data functions with a page value
      of -1, intending to perform the operation without setting the page.
      However, the read/write word data functions accept only unsigned 8-bit
      page numbers, and therefore cannot check for negative page number to
      avoid setting the page. This results in setting the page number to 0xFF.
      This may result in errors or undefined behavior of some devices
      (specifically the ir35221, which allows the page to be set to 0xFF,
      but some subsequent operations to read registers may fail).
      
      Switch the pmbus_set_page page parameter to an integer and perform the
      check for negative page there. Make read/write functions consistent in
      accepting an integer page number parameter.
      Signed-off-by: NEdward A. James <eajames@us.ibm.com>
      Fixes: cbcdec62 ("hwmon: (pmbus): Access word data for STATUS_WORD")
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      6dcf2fb5
  5. 30 8月, 2017 1 次提交
  6. 15 8月, 2017 1 次提交
  7. 13 8月, 2017 3 次提交
  8. 12 6月, 2017 1 次提交
  9. 20 8月, 2015 1 次提交
  10. 10 8月, 2015 3 次提交
  11. 01 12月, 2014 2 次提交
  12. 03 2月, 2014 1 次提交
  13. 19 10月, 2013 1 次提交
  14. 14 10月, 2013 2 次提交
  15. 12 8月, 2013 1 次提交
  16. 14 3月, 2013 1 次提交
  17. 07 2月, 2013 11 次提交
  18. 26 1月, 2013 1 次提交
  19. 10 10月, 2012 2 次提交
  20. 10 4月, 2012 1 次提交
  21. 19 3月, 2012 1 次提交