• Ido Schimmel's avatar
    thermal/of: Fix memory leak on thermal_of_zone_register() failure · 7ef2f023
    Ido Schimmel authored
    The function does not free 'of_ops' upon failure, leading to a memory
    leak [1].
    
    Fix by freeing 'of_ops' in the error path.
    
    [1]
    unreferenced object 0xffff8ee846198c80 (size 128):
      comm "swapper/0", pid 1, jiffies 4294699704 (age 70.076s)
      hex dump (first 32 bytes):
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        d0 3f 6e 8c ff ff ff ff 00 00 00 00 00 00 00 00  .?n.............
      backtrace:
        [<00000000d136f562>] __kmalloc_node_track_caller+0x42/0x120
        [<0000000063f31678>] kmemdup+0x1d/0x40
        [<00000000e6d24096>] thermal_of_zone_register+0x49/0x520
        [<000000005e78c755>] devm_thermal_of_zone_register+0x54/0x90
        [<00000000ee6b209e>] pmbus_add_sensor+0x1b4/0x1d0
        [<00000000896105e3>] pmbus_add_sensor_attrs_one+0x123/0x440
        [<0000000049e990a6>] pmbus_add_sensor_attrs+0xfe/0x1d0
        [<00000000466b5440>] pmbus_do_probe+0x66b/0x14e0
        [<0000000084d42285>] i2c_device_probe+0x13b/0x2f0
        [<0000000029e2ae74>] really_probe+0xce/0x2c0
        [<00000000692df15c>] driver_probe_device+0x19/0xd0
        [<00000000547d9cce>] __device_attach_driver+0x6f/0x100
        [<0000000020abd24b>] bus_for_each_drv+0x76/0xc0
        [<00000000665d9563>] __device_attach+0xfc/0x180
        [<000000008ddd4d6a>] bus_probe_device+0x82/0xa0
        [<000000009e61132b>] device_add+0x3fe/0x920
    
    Fixes: 3fd6d6e2 ("thermal/of: Rework the thermal device tree initialization")
    Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
    Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
    Link: https://lore.kernel.org/r/20221020103658.802457-1-idosch@nvidia.comSigned-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
    7ef2f023
thermal_of.c 18.1 KB