Skip to content
  1. Jan 07, 2023
    • ZhangPeng's avatar
      hfs: fix OOB Read in __hfs_brec_find · 8c40f2db
      ZhangPeng authored
      [ Upstream commit 8d824e69
      
       ]
      
      Syzbot reported a OOB read bug:
      
      ==================================================================
      BUG: KASAN: slab-out-of-bounds in hfs_strcmp+0x117/0x190
      fs/hfs/string.c:84
      Read of size 1 at addr ffff88807eb62c4e by task kworker/u4:1/11
      CPU: 1 PID: 11 Comm: kworker/u4:1 Not tainted
      6.1.0-rc6-syzkaller-00308-g644e9524388a #0
      Workqueue: writeback wb_workfn (flush-7:0)
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
       print_address_description+0x74/0x340 mm/kasan/report.c:284
       print_report+0x107/0x1f0 mm/kasan/report.c:395
       kasan_report+0xcd/0x100 mm/kasan/report.c:495
       hfs_strcmp+0x117/0x190 fs/hfs/string.c:84
       __hfs_brec_find+0x213/0x5c0 fs/hfs/bfind.c:75
       hfs_brec_find+0x276/0x520 fs/hfs/bfind.c:138
       hfs_write_inode+0x34c/0xb40 fs/hfs/inode.c:462
       write_inode fs/fs-writeback.c:1440 [inline]
      
      If the input inode of hfs_write_inode() is incorrect:
      struct inode
        struct hfs_inode_info
          struct hfs_cat_key
            struct hfs_name
              u8 len # len is greater than HFS_NAMELEN(31) which is the
      maximum length of an HFS filename
      
      OOB read occurred:
      hfs_write_inode()
        hfs_brec_find()
          __hfs_brec_find()
            hfs_cat_keycmp()
              hfs_strcmp() # OOB read occurred due to len is too large
      
      Fix this by adding a Check on len in hfs_write_inode() before calling
      hfs_brec_find().
      
      Link: https://lkml.kernel.org/r/20221130065959.2168236-1-zhangpeng362@huawei.com
      Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
      Reported-by: default avatar <syzbot+e836ff7133ac02be825f@syzkaller.appspotmail.com>
      Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
      Cc: Ira Weiny <ira.weiny@intel.com>
      Cc: Jeff Layton <jlayton@kernel.org>
      Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Nanyong Sun <sunnanyong@huawei.com>
      Cc: Viacheslav Dubeyko <slava@dubeyko.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8c40f2db
    • Zheng Yejian's avatar
      acct: fix potential integer overflow in encode_comp_t() · e93f995a
      Zheng Yejian authored
      [ Upstream commit c5f31c65
      
       ]
      
      The integer overflow is descripted with following codes:
        > 317 static comp_t encode_comp_t(u64 value)
        > 318 {
        > 319         int exp, rnd;
          ......
        > 341         exp <<= MANTSIZE;
        > 342         exp += value;
        > 343         return exp;
        > 344 }
      
      Currently comp_t is defined as type of '__u16', but the variable 'exp' is
      type of 'int', so overflow would happen when variable 'exp' in line 343 is
      greater than 65535.
      
      Link: https://lkml.kernel.org/r/20210515140631.369106-3-zhengyejian1@huawei.com
      Signed-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
      Cc: Hanjun Guo <guohanjun@huawei.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Zhang Jinhao <zhangjinhao2@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e93f995a
    • Ryusuke Konishi's avatar
      nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset() · 6b0ea3df
      Ryusuke Konishi authored
      [ Upstream commit 610a2a3d
      
       ]
      
      Patch series "nilfs2: fix UBSAN shift-out-of-bounds warnings on mount
      time".
      
      The first patch fixes a bug reported by syzbot, and the second one fixes
      the remaining bug of the same kind.  Although they are triggered by the
      same super block data anomaly, I divided it into the above two because the
      details of the issues and how to fix it are different.
      
      Both are required to eliminate the shift-out-of-bounds issues at mount
      time.
      
      This patch (of 2):
      
      If the block size exponent information written in an on-disk superblock is
      corrupted, nilfs_sb2_bad_offset helper function can trigger
      shift-out-of-bounds warning followed by a kernel panic (if panic_on_warn
      is set):
      
       shift exponent 38983 is too large for 64-bit type 'unsigned long long'
       Call Trace:
        <TASK>
        __dump_stack lib/dump_stack.c:88 [inline]
        dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
        ubsan_epilogue lib/ubsan.c:151 [inline]
        __ubsan_handle_shift_out_of_bounds+0x33d/0x3b0 lib/ubsan.c:322
        nilfs_sb2_bad_offset fs/nilfs2/the_nilfs.c:449 [inline]
        nilfs_load_super_block+0xdf5/0xe00 fs/nilfs2/the_nilfs.c:523
        init_nilfs+0xb7/0x7d0 fs/nilfs2/the_nilfs.c:577
        nilfs_fill_super+0xb1/0x5d0 fs/nilfs2/super.c:1047
        nilfs_mount+0x613/0x9b0 fs/nilfs2/super.c:1317
        ...
      
      In addition, since nilfs_sb2_bad_offset() performs multiplication without
      considering the upper bound, the computation may overflow if the disk
      layout parameters are not normal.
      
      This fixes these issues by inserting preliminary sanity checks for those
      parameters and by converting the comparison from one involving
      multiplication and left bit-shifting to one using division and right
      bit-shifting.
      
      Link: https://lkml.kernel.org/r/20221027044306.42774-1-konishi.ryusuke@gmail.com
      Link: https://lkml.kernel.org/r/20221027044306.42774-2-konishi.ryusuke@gmail.com
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Reported-by: default avatar <syzbot+e91619dd4c11c4960706@syzkaller.appspotmail.com>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6b0ea3df
    • Rafael J. Wysocki's avatar
      ACPICA: Fix error code path in acpi_ds_call_control_method() · 38e251d3
      Rafael J. Wysocki authored
      [ Upstream commit 404ec604
      
       ]
      
      A use-after-free in acpi_ps_parse_aml() after a failing invocaion of
      acpi_ds_call_control_method() is reported by KASAN [1] and code
      inspection reveals that next_walk_state pushed to the thread by
      acpi_ds_create_walk_state() is freed on errors, but it is not popped
      from the thread beforehand.  Thus acpi_ds_get_current_walk_state()
      called by acpi_ps_parse_aml() subsequently returns it as the new
      walk state which is incorrect.
      
      To address this, make acpi_ds_call_control_method() call
      acpi_ds_pop_walk_state() to pop next_walk_state from the thread before
      returning an error.
      
      Link: https://lore.kernel.org/linux-acpi/20221019073443.248215-1-chenzhongjin@huawei.com/ # [1]
      Reported-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      38e251d3
    • Hoi Pok Wu's avatar
      fs: jfs: fix shift-out-of-bounds in dbDiscardAG · f8d4d0ba
      Hoi Pok Wu authored
      [ Upstream commit 25e70c61
      
       ]
      
      This should be applied to most URSAN bugs found recently by syzbot,
      by guarding the dbMount. As syzbot feeding rubbish into the bmap
      descriptor.
      
      Signed-off-by: default avatarHoi Pok Wu <wuhoipok@gmail.com>
      Signed-off-by: default avatarDave Kleikamp <dave.kleikamp@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f8d4d0ba
    • Shigeru Yoshida's avatar
      udf: Avoid double brelse() in udf_rename() · 78eba277
      Shigeru Yoshida authored
      [ Upstream commit c791730f
      
       ]
      
      syzbot reported a warning like below [1]:
      
      VFS: brelse: Trying to free free buffer
      WARNING: CPU: 2 PID: 7301 at fs/buffer.c:1145 __brelse+0x67/0xa0
      ...
      Call Trace:
       <TASK>
       invalidate_bh_lru+0x99/0x150
       smp_call_function_many_cond+0xe2a/0x10c0
       ? generic_remap_file_range_prep+0x50/0x50
       ? __brelse+0xa0/0xa0
       ? __mutex_lock+0x21c/0x12d0
       ? smp_call_on_cpu+0x250/0x250
       ? rcu_read_lock_sched_held+0xb/0x60
       ? lock_release+0x587/0x810
       ? __brelse+0xa0/0xa0
       ? generic_remap_file_range_prep+0x50/0x50
       on_each_cpu_cond_mask+0x3c/0x80
       blkdev_flush_mapping+0x13a/0x2f0
       blkdev_put_whole+0xd3/0xf0
       blkdev_put+0x222/0x760
       deactivate_locked_super+0x96/0x160
       deactivate_super+0xda/0x100
       cleanup_mnt+0x222/0x3d0
       task_work_run+0x149/0x240
       ? task_work_cancel+0x30/0x30
       do_exit+0xb29/0x2a40
       ? reacquire_held_locks+0x4a0/0x4a0
       ? do_raw_spin_lock+0x12a/0x2b0
       ? mm_update_next_owner+0x7c0/0x7c0
       ? rwlock_bug.part.0+0x90/0x90
       ? zap_other_threads+0x234/0x2d0
       do_group_exit+0xd0/0x2a0
       __x64_sys_exit_group+0x3a/0x50
       do_syscall_64+0x34/0xb0
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      The cause of the issue is that brelse() is called on both ofibh.sbh
      and ofibh.ebh by udf_find_entry() when it returns NULL.  However,
      brelse() is called by udf_rename(), too.  So, b_count on buffer_head
      becomes unbalanced.
      
      This patch fixes the issue by not calling brelse() by udf_rename()
      when udf_find_entry() returns NULL.
      
      Link: https://syzkaller.appspot.com/bug?id=8297f45698159c6bca8a1f87dc983667c1a1c851 [1]
      Reported-by: default avatar <syzbot+7902cd7684bc35306224@syzkaller.appspotmail.com>
      Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20221023095741.271430-1-syoshida@redhat.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      78eba277
    • Dongliang Mu's avatar
      fs: jfs: fix shift-out-of-bounds in dbAllocAG · d3b48694
      Dongliang Mu authored
      [ Upstream commit 898f7066
      
       ]
      
      Syzbot found a crash : UBSAN: shift-out-of-bounds in dbAllocAG. The
      underlying bug is the missing check of bmp->db_agl2size. The field can
      be greater than 64 and trigger the shift-out-of-bounds.
      
      Fix this bug by adding a check of bmp->db_agl2size in dbMount since this
      field is used in many following functions. The upper bound for this
      field is L2MAXL2SIZE - L2MAXAG, thanks for the help of Dave Kleikamp.
      Note that, for maintenance, I reorganized error handling code of dbMount.
      
      Reported-by: default avatar <syzbot+15342c1aa6a00fb7a438@syzkaller.appspotmail.com>
      Signed-off-by: default avatarDongliang Mu <mudongliangabcd@gmail.com>
      Signed-off-by: default avatarDave Kleikamp <dave.kleikamp@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d3b48694
    • Liu Shixin's avatar
      binfmt_misc: fix shift-out-of-bounds in check_special_flags · 0f1a4899
      Liu Shixin authored
      [ Upstream commit 6a46bf55
      
       ]
      
      UBSAN reported a shift-out-of-bounds warning:
      
       left shift of 1 by 31 places cannot be represented in type 'int'
       Call Trace:
        <TASK>
        __dump_stack lib/dump_stack.c:88 [inline]
        dump_stack_lvl+0x8d/0xcf lib/dump_stack.c:106
        ubsan_epilogue+0xa/0x44 lib/ubsan.c:151
        __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 lib/ubsan.c:322
        check_special_flags fs/binfmt_misc.c:241 [inline]
        create_entry fs/binfmt_misc.c:456 [inline]
        bm_register_write+0x9d3/0xa20 fs/binfmt_misc.c:654
        vfs_write+0x11e/0x580 fs/read_write.c:582
        ksys_write+0xcf/0x120 fs/read_write.c:637
        do_syscall_x64 arch/x86/entry/common.c:50 [inline]
        do_syscall_64+0x34/0x80 arch/x86/entry/common.c:80
        entry_SYSCALL_64_after_hwframe+0x63/0xcd
       RIP: 0033:0x4194e1
      
      Since the type of Node's flags is unsigned long, we should define these
      macros with same type too.
      
      Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20221102025123.1117184-1-liushixin2@huawei.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0f1a4899
    • Eric Dumazet's avatar
      net: stream: purge sk_error_queue in sk_stream_kill_queues() · c8c1eec5
      Eric Dumazet authored
      [ Upstream commit e0c8bccd ]
      
      Changheon Lee reported TCP socket leaks, with a nice repro.
      
      It seems we leak TCP sockets with the following sequence:
      
      1) SOF_TIMESTAMPING_TX_ACK is enabled on the socket.
      
         Each ACK will cook an skb put in error queue, from __skb_tstamp_tx().
         __skb_tstamp_tx() is using skb_clone(), unless
         SOF_TIMESTAMPING_OPT_TSONLY was also requested.
      
      2) If the application is also using MSG_ZEROCOPY, then we put in the
         error queue cloned skbs that had a struct ubuf_info attached to them.
      
         Whenever an struct ubuf_info is allocated, sock_zerocopy_alloc()
         does a sock_hold().
      
         As long as the cloned skbs are still in sk_error_queue,
         socket refcount is kept elevated.
      
      3) Application closes the socket, while error queue is not empty.
      
      Since tcp_close() no longer purges the socket error queue,
      we might end up with a TCP socket with at least one skb in
      error queue keeping the socket alive forever.
      
      This bug can be (ab)used to consume all kernel memory
      and freeze the host.
      
      We need to purge the error queue, with proper synchronization
      against concurrent writers.
      
      Fixes: 24bcbe1c
      
       ("net: stream: don't purge sk_error_queue in sk_stream_kill_queues()")
      Reported-by: default avatarChangheon Lee <darklight2357@icloud.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c8c1eec5
    • Christophe JAILLET's avatar
      myri10ge: Fix an error handling path in myri10ge_probe() · a4da73a1
      Christophe JAILLET authored
      [ Upstream commit d83b950d ]
      
      Some memory allocated in myri10ge_probe_slices() is not released in the
      error handling path of myri10ge_probe().
      
      Add the corresponding kfree(), as already done in the remove function.
      
      Fixes: 0dcffac1
      
       ("myri10ge: add multislices support")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a4da73a1
    • Cong Wang's avatar
      net_sched: reject TCF_EM_SIMPLE case for complex ematch module · 4d5d13ea
      Cong Wang authored
      [ Upstream commit 9cd3fd20 ]
      
      When TCF_EM_SIMPLE was introduced, it is supposed to be convenient
      for ematch implementation:
      
      https://lore.kernel.org/all/20050105110048.GO26856@postel.suug.ch/
      
      "You don't have to, providing a 32bit data chunk without TCF_EM_SIMPLE
      set will simply result in allocating & copy. It's an optimization,
      nothing more."
      
      So if an ematch module provides ops->datalen that means it wants a
      complex data structure (saved in its em->data) instead of a simple u32
      value. We should simply reject such a combination, otherwise this u32
      could be misinterpreted as a pointer.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Reported-and-tested-by: default avatar <syzbot+4caeae4c7103813598ae@syzkaller.appspotmail.com>
      Reported-by: default avatarJun Nie <jun.nie@linaro.org>
      Cc: Jamal Hadi Salim <jhs@mojatatu.com>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
      Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4d5d13ea
    • Subash Abhinov Kasiviswanathan's avatar
      skbuff: Account for tail adjustment during pull operations · ff3743d0
      Subash Abhinov Kasiviswanathan authored
      [ Upstream commit 2d7afdcb ]
      
      Extending the tail can have some unexpected side effects if a program uses
      a helper like BPF_FUNC_skb_pull_data to read partial content beyond the
      head skb headlen when all the skbs in the gso frag_list are linear with no
      head_frag -
      
        kernel BUG at net/core/skbuff.c:4219!
        pc : skb_segment+0xcf4/0xd2c
        lr : skb_segment+0x63c/0xd2c
        Call trace:
         skb_segment+0xcf4/0xd2c
         __udp_gso_segment+0xa4/0x544
         udp4_ufo_fragment+0x184/0x1c0
         inet_gso_segment+0x16c/0x3a4
         skb_mac_gso_segment+0xd4/0x1b0
         __skb_gso_segment+0xcc/0x12c
         udp_rcv_segment+0x54/0x16c
         udp_queue_rcv_skb+0x78/0x144
         udp_unicast_rcv_skb+0x8c/0xa4
         __udp4_lib_rcv+0x490/0x68c
         udp_rcv+0x20/0x30
         ip_protocol_deliver_rcu+0x1b0/0x33c
         ip_local_deliver+0xd8/0x1f0
         ip_rcv+0x98/0x1a4
         deliver_ptype_list_skb+0x98/0x1ec
         __netif_receive_skb_core+0x978/0xc60
      
      Fix this by marking these skbs as GSO_DODGY so segmentation can handle
      the tail updates accordingly.
      
      Fixes: 3dcbdb13
      
       ("net: gso: Fix skb_segment splat when splitting gso_size mangled skb having linear-headed frag_list")
      Signed-off-by: default avatarSean Tranchetti <quic_stranche@quicinc.com>
      Signed-off-by: default avatarSubash Abhinov Kasiviswanathan <quic_subashab@quicinc.com>
      Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
      Link: https://lore.kernel.org/r/1671084718-24796-1-git-send-email-quic_subashab@quicinc.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ff3743d0
    • Eelco Chaudron's avatar
      openvswitch: Fix flow lookup to use unmasked key · 4f592e71
      Eelco Chaudron authored
      [ Upstream commit 68bb1010 ]
      
      The commit mentioned below causes the ovs_flow_tbl_lookup() function
      to be called with the masked key. However, it's supposed to be called
      with the unmasked key. This due to the fact that the datapath supports
      installing wider flows, and OVS relies on this behavior. For example
      if ipv4(src=1.1.1.1/192.0.0.0, dst=1.1.1.2/192.0.0.0) exists, a wider
      flow (smaller mask) of ipv4(src=192.1.1.1/128.0.0.0,dst=192.1.1.2/
      128.0.0.0) is allowed to be added.
      
      However, if we try to add a wildcard rule, the installation fails:
      
      $ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \
        ipv4(src=1.1.1.1/192.0.0.0,dst=1.1.1.2/192.0.0.0,frag=no)" 2
      $ ovs-appctl dpctl/add-flow system@myDP "in_port(1),eth_type(0x0800), \
        ipv4(src=192.1.1.1/0.0.0.0,dst=49.1.1.2/0.0.0.0,frag=no)" 2
      ovs-vswitchd: updating flow table (File exists)
      
      The reason is that the key used to determine if the flow is already
      present in the system uses the original key ANDed with the mask.
      This results in the IP address not being part of the (miniflow) key,
      i.e., being substituted with an all-zero value. When doing the actual
      lookup, this results in the key wrongfully matching the first flow,
      and therefore the flow does not get installed.
      
      This change reverses the commit below, but rather than having the key
      on the stack, it's allocated.
      
      Fixes: 190aa3e7
      
       ("openvswitch: Fix Frame-size larger than 1024 bytes warning.")
      
      Signed-off-by: default avatarEelco Chaudron <echaudro@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4f592e71
    • Li Zetao's avatar
      r6040: Fix kmemleak in probe and remove · a04707f4
      Li Zetao authored
      [ Upstream commit 7e43039a ]
      
      There is a memory leaks reported by kmemleak:
      
        unreferenced object 0xffff888116111000 (size 2048):
          comm "modprobe", pid 817, jiffies 4294759745 (age 76.502s)
          hex dump (first 32 bytes):
            00 c4 0a 04 81 88 ff ff 08 10 11 16 81 88 ff ff  ................
            08 10 11 16 81 88 ff ff 00 00 00 00 00 00 00 00  ................
          backtrace:
            [<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
            [<ffffffff827e20ee>] phy_device_create+0x4e/0x90
            [<ffffffff827e6072>] get_phy_device+0xd2/0x220
            [<ffffffff827e7844>] mdiobus_scan+0xa4/0x2e0
            [<ffffffff827e8be2>] __mdiobus_register+0x482/0x8b0
            [<ffffffffa01f5d24>] r6040_init_one+0x714/0xd2c [r6040]
            ...
      
      The problem occurs in probe process as follows:
        r6040_init_one:
          mdiobus_register
            mdiobus_scan    <- alloc and register phy_device,
                               the reference count of phy_device is 3
          r6040_mii_probe
            phy_connect     <- connect to the first phy_device,
                               so the reference count of the first
                               phy_device is 4, others are 3
          register_netdev   <- fault inject succeeded, goto error handling path
      
          // error handling path
          err_out_mdio_unregister:
            mdiobus_unregister(lp->mii_bus);
          err_out_mdio:
            mdiobus_free(lp->mii_bus);    <- the reference count of the first
                                             phy_device is 1, it is not released
                                             and other phy_devices are released
        // similarly, the remove process also has the same problem
      
      The root cause is traced to the phy_device is not disconnected when
      removes one r6040 device in r6040_remove_one() or on error handling path
      after r6040_mii probed successfully. In r6040_mii_probe(), a net ethernet
      device is connected to the first PHY device of mii_bus, in order to
      notify the connected driver when the link status changes, which is the
      default behavior of the PHY infrastructure to handle everything.
      Therefore the phy_device should be disconnected when removes one r6040
      device or on error handling path.
      
      Fix it by adding phy_disconnect() when removes one r6040 device or on
      error handling path after r6040_mii probed successfully.
      
      Fixes: 3831861b
      
       ("r6040: implement phylib")
      Signed-off-by: default avatarLi Zetao <lizetao1@huawei.com>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Link: https://lore.kernel.org/r/20221213125614.927754-1-lizetao1@huawei.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a04707f4
    • Minsuk Kang's avatar
      nfc: pn533: Clear nfc_target before being used · 9da4a041
      Minsuk Kang authored
      [ Upstream commit 9f281577 ]
      
      Fix a slab-out-of-bounds read that occurs in nla_put() called from
      nfc_genl_send_target() when target->sensb_res_len, which is duplicated
      from an nfc_target in pn533, is too large as the nfc_target is not
      properly initialized and retains garbage values. Clear nfc_targets with
      memset() before they are used.
      
      Found by a modified version of syzkaller.
      
      BUG: KASAN: slab-out-of-bounds in nla_put
      Call Trace:
       memcpy
       nla_put
       nfc_genl_dump_targets
       genl_lock_dumpit
       netlink_dump
       __netlink_dump_start
       genl_family_rcv_msg_dumpit
       genl_rcv_msg
       netlink_rcv_skb
       genl_rcv
       netlink_unicast
       netlink_sendmsg
       sock_sendmsg
       ____sys_sendmsg
       ___sys_sendmsg
       __sys_sendmsg
       do_syscall_64
      
      Fixes: 673088fb ("NFC: pn533: Send ATR_REQ directly for active device detection")
      Fixes: 361f3cb7
      
       ("NFC: DEP link hook implementation for pn533")
      Signed-off-by: default avatarMinsuk Kang <linuxlovemin@yonsei.ac.kr>
      Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Link: https://lore.kernel.org/r/20221214015139.119673-1-linuxlovemin@yonsei.ac.kr
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9da4a041
    • Yang Yingliang's avatar
      mISDN: hfcmulti: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() · 7f1cda9c
      Yang Yingliang authored
      [ Upstream commit 1232946c ]
      
      It is not allowed to call kfree_skb() or consume_skb() from hardware
      interrupt context or with hardware interrupts being disabled.
      
      skb_queue_purge() is called under spin_lock_irqsave() in handle_dmsg()
      and hfcm_l1callback(), kfree_skb() is called in them, to fix this, use
      skb_queue_splice_init() to move the dch->squeue to a free queue, also
      enqueue the tx_skb and rx_skb, at last calling __skb_queue_purge() to
      free the SKBs afer unlock.
      
      Fixes: af69fb3a
      
       ("Add mISDN HFC multiport driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f1cda9c
    • Yang Yingliang's avatar
      mISDN: hfcpci: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() · fc24113b
      Yang Yingliang authored
      [ Upstream commit f0f596bd ]
      
      It is not allowed to call kfree_skb() or consume_skb() from hardware
      interrupt context or with hardware interrupts being disabled.
      
      skb_queue_purge() is called under spin_lock_irqsave() in hfcpci_l2l1D(),
      kfree_skb() is called in it, to fix this, use skb_queue_splice_init()
      to move the dch->squeue to a free queue, also enqueue the tx_skb and
      rx_skb, at last calling __skb_queue_purge() to free the SKBs afer unlock.
      
      Fixes: 1700fe1a
      
       ("Add mISDN HFC PCI driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fc24113b
    • Yang Yingliang's avatar
      mISDN: hfcsusb: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() · 291b7879
      Yang Yingliang authored
      [ Upstream commit ddc9648d ]
      
      It is not allowed to call kfree_skb() or consume_skb() from hardware
      interrupt context or with hardware interrupts being disabled.
      
      It should use dev_kfree_skb_irq() or dev_consume_skb_irq() instead.
      The difference between them is free reason, dev_kfree_skb_irq() means
      the SKB is dropped in error and dev_consume_skb_irq() means the SKB
      is consumed in normal.
      
      skb_queue_purge() is called under spin_lock_irqsave() in hfcusb_l2l1D(),
      kfree_skb() is called in it, to fix this, use skb_queue_splice_init()
      to move the dch->squeue to a free queue, also enqueue the tx_skb and
      rx_skb, at last calling __skb_queue_purge() to free the SKBs afer unlock.
      
      In tx_iso_complete(), dev_kfree_skb() is called to consume the transmitted
      SKB, so replace it with dev_consume_skb_irq().
      
      Fixes: 69f52adb
      
       ("mISDN: Add HFC USB driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      291b7879
    • Dan Aloni's avatar
      nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure · 707bcca9
      Dan Aloni authored
      [ Upstream commit 3bc8edc9 ]
      
      On error situation `clp->cl_cb_conn.cb_xprt` should not be given
      a reference to the xprt otherwise both client cleanup and the
      error handling path of the caller call to put it. Better to
      delay handing over the reference to a later branch.
      
      [   72.530665] refcount_t: underflow; use-after-free.
      [   72.531933] WARNING: CPU: 0 PID: 173 at lib/refcount.c:28 refcount_warn_saturate+0xcf/0x120
      [   72.533075] Modules linked in: nfsd(OE) nfsv4(OE) nfsv3(OE) nfs(OE) lockd(OE) compat_nfs_ssc(OE) nfs_acl(OE) rpcsec_gss_krb5(OE) auth_rpcgss(OE) rpcrdma(OE) dns_resolver fscache netfs grace rdma_cm iw_cm ib_cm sunrpc(OE) mlx5_ib mlx5_core mlxfw pci_hyperv_intf ib_uverbs ib_core xt_MASQUERADE nf_conntrack_netlink nft_counter xt_addrtype nft_compat br_netfilter bridge stp llc nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set overlay nf_tables nfnetlink crct10dif_pclmul crc32_pclmul ghash_clmulni_intel xfs serio_raw virtio_net virtio_blk net_failover failover fuse [last unloaded: sunrpc]
      [   72.540389] CPU: 0 PID: 173 Comm: kworker/u16:5 Tainted: G           OE     5.15.82-dan #1
      [   72.541511] Hardware name: Red Hat KVM/RHEL-AV, BIOS 1.16.0-3.module+el8.7.0+1084+97b81f61 04/01/2014
      [   72.542717] Workqueue: nfsd4_callbacks nfsd4_run_cb_work [nfsd]
      [   72.543575] RIP: 0010:refcount_warn_saturate+0xcf/0x120
      [   72.544299] Code: 55 00 0f 0b 5d e9 01 50 98 00 80 3d 75 9e 39 08 00 0f 85 74 ff ff ff 48 c7 c7 e8 d1 60 8e c6 05 61 9e 39 08 01 e8 f6 51 55 00 <0f> 0b 5d e9 d9 4f 98 00 80 3d 4b 9e 39 08 00 0f 85 4c ff ff ff 48
      [   72.546666] RSP: 0018:ffffb3f841157cf0 EFLAGS: 00010286
      [   72.547393] RAX: 0000000000000026 RBX: ffff89ac6231d478 RCX: 0000000000000000
      [   72.548324] RDX: ffff89adb7c2c2c0 RSI: ffff89adb7c205c0 RDI: ffff89adb7c205c0
      [   72.549271] RBP: ffffb3f841157cf0 R08: 0000000000000000 R09: c0000000ffefffff
      [   72.550209] R10: 0000000000000001 R11: ffffb3f841157ad0 R12: ffff89ac6231d180
      [   72.551142] R13: ffff89ac6231d478 R14: ffff89ac40c06180 R15: ffff89ac6231d4b0
      [   72.552089] FS:  0000000000000000(0000) GS:ffff89adb7c00000(0000) knlGS:0000000000000000
      [   72.553175] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   72.553934] CR2: 0000563a310506a8 CR3: 0000000109a66000 CR4: 0000000000350ef0
      [   72.554874] Call Trace:
      [   72.555278]  <TASK>
      [   72.555614]  svc_xprt_put+0xaf/0xe0 [sunrpc]
      [   72.556276]  nfsd4_process_cb_update.isra.11+0xb7/0x410 [nfsd]
      [   72.557087]  ? update_load_avg+0x82/0x610
      [   72.557652]  ? cpuacct_charge+0x60/0x70
      [   72.558212]  ? dequeue_entity+0xdb/0x3e0
      [   72.558765]  ? queued_spin_unlock+0x9/0x20
      [   72.559358]  nfsd4_run_cb_work+0xfc/0x270 [nfsd]
      [   72.560031]  process_one_work+0x1df/0x390
      [   72.560600]  worker_thread+0x37/0x3b0
      [   72.561644]  ? process_one_work+0x390/0x390
      [   72.562247]  kthread+0x12f/0x150
      [   72.562710]  ? set_kthread_struct+0x50/0x50
      [   72.563309]  ret_from_fork+0x22/0x30
      [   72.563818]  </TASK>
      [   72.564189] ---[ end trace 031117b1c72ec616 ]---
      [   72.566019] list_add corruption. next->prev should be prev (ffff89ac4977e538), but was ffff89ac4763e018. (next=ffff89ac4763e018).
      [   72.567647] ------------[ cut here ]------------
      
      Fixes: a4abc6b1
      
       ("nfsd: Fix svc_xprt refcnt leak when setup callback client failed")
      Cc: Xiyu Yang <xiyuyang19@fudan.edu.cn>
      Cc: J. Bruce Fields <bfields@redhat.com>
      Signed-off-by: default avatarDan Aloni <dan.aloni@vastdata.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      707bcca9
    • Gaosheng Cui's avatar
      rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe() · 4761ab97
      Gaosheng Cui authored
      [ Upstream commit 5fb733d7 ]
      
      The clk_disable_unprepare() should be called in the error handling
      of clk_get_rate(), fix it.
      
      Fixes: b5b2bdfc
      
       ("rtc: st: Add new driver for ST's LPC RTC")
      Signed-off-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Link: https://lore.kernel.org/r/20221123014805.1993052-1-cuigaosheng1@huawei.com
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4761ab97
    • Miaoqian Lin's avatar
      selftests/powerpc: Fix resource leaks · 81a61f33
      Miaoqian Lin authored
      [ Upstream commit 8f4ab7da ]
      
      In check_all_cpu_dscr_defaults, opendir() opens the directory stream.
      Add missing closedir() in the error path to release it.
      
      In check_cpu_dscr_default, open() creates an open file descriptor.
      Add missing close() in the error path to release it.
      
      Fixes: ebd5858c
      
       ("selftests/powerpc: Add test for all DSCR sysfs interfaces")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20221205084429.570654-1-linmq006@gmail.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      81a61f33
    • Kajol Jain's avatar
      powerpc/hv-gpci: Fix hv_gpci event list · 1bd37681
      Kajol Jain authored
      [ Upstream commit 03f7c1d2 ]
      
      Based on getPerfCountInfo v1.018 documentation, some of the
      hv_gpci events were deprecated for platform firmware that
      supports counter_info_version 0x8 or above.
      
      Fix the hv_gpci event list by adding a new attribute group
      called "hv_gpci_event_attrs_v6" and a "ENABLE_EVENTS_COUNTERINFO_V6"
      macro to enable these events for platform firmware
      that supports counter_info_version 0x6 or below. And assigning
      the hv_gpci event list based on output counter info version
      of underlying plaform.
      
      Fixes: 97bf2640
      
       ("powerpc/perf/hv-gpci: add the remaining gpci requests")
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.ibm.com>
      Reviewed-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20221130174513.87501-1-kjain@linux.ibm.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1bd37681
    • Yang Yingliang's avatar
      powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe() · 225c8523
      Yang Yingliang authored
      [ Upstream commit 4d0eea41 ]
      
      If platform_device_add() is not called or failed, it can not call
      platform_device_del() to clean up memory, it should call
      platform_device_put() in error case.
      
      Fixes: 26f6cb99
      
       ("[POWERPC] fsl_soc: add support for fsl_spi")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20221029111626.429971-1-yangyingliang@huawei.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      225c8523
    • Nicholas Piggin's avatar
      powerpc/perf: callchain validate kernel stack pointer bounds · 4a62ab09
      Nicholas Piggin authored
      [ Upstream commit 32c52092 ]
      
      The interrupt frame detection and loads from the hypothetical pt_regs
      are not bounds-checked. The next-frame validation only bounds-checks
      STACK_FRAME_OVERHEAD, which does not include the pt_regs. Add another
      test for this.
      
      The user could set r1 to be equal to the address matching the first
      interrupt frame - STACK_INT_FRAME_SIZE, which is in the previous page
      due to the kernel redzone, and induce the kernel to load the marker from
      there. Possibly this could cause a crash at least. If the user could
      induce the previous page to contain a valid marker, then it might be
      able to direct perf to read specific memory addresses in a way that
      could be transmitted back to the user in the perf data.
      
      Fixes: 20002ded
      
       ("perf_counter: powerpc: Add callchain support")
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20221127124942.1665522-4-npiggin@gmail.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4a62ab09
    • Christophe JAILLET's avatar
      powerpc/52xx: Fix a resource leak in an error handling path · be9caf2c
      Christophe JAILLET authored
      [ Upstream commit 58369476 ]
      
      The error handling path of mpc52xx_lpbfifo_probe() has a request_irq()
      that is not balanced by a corresponding free_irq().
      
      Add the missing call, as already done in the remove function.
      
      Fixes: 3c9059d7
      
       ("powerpc/5200: add LocalPlus bus FIFO device driver")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/dec1496d46ccd5311d0f6e9f9ca4238be11bf6a6.1643440531.git.christophe.jaillet@wanadoo.fr
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      be9caf2c
    • Xie Shaowen's avatar
      macintosh/macio-adb: check the return value of ioremap() · aaf59a44
      Xie Shaowen authored
      [ Upstream commit dbaa3105 ]
      
      The function ioremap() in macio_init() can fail, so its return value
      should be checked.
      
      Fixes: 36874579
      
       ("[PATCH] powerpc: macio-adb build fix")
      Reported-by: default avatarHacash Robot <hacashRobot@santino.com>
      Signed-off-by: default avatarXie Shaowen <studentxswpy@163.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20220802074148.3213659-1-studentxswpy@163.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aaf59a44
    • Yang Yingliang's avatar
      macintosh: fix possible memory leak in macio_add_one_device() · 3a866ff6
      Yang Yingliang authored
      [ Upstream commit 5ca86eae ]
      
      Afer commit 1fa5ae85 ("driver core: get rid of struct device's
      bus_id string array"), the name of device is allocated dynamically. It
      needs to be freed when of_device_register() fails. Call put_device() to
      give up the reference that's taken in device_initialize(), so that it
      can be freed in kobject_cleanup() when the refcount hits 0.
      
      macio device is freed in macio_release_dev(), so the kfree() can be
      removed.
      
      Fixes: 1fa5ae85
      
       ("driver core: get rid of struct device's bus_id string array")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20221104032551.1075335-1-yangyingliang@huawei.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3a866ff6
    • Yuan Can's avatar
      iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe() · c9398323
      Yuan Can authored
      [ Upstream commit 73f5fc5f ]
      
      The fsl_pamu_probe() returns directly when create_csd() failed, leaving
      irq and memories unreleased.
      Fix by jumping to error if create_csd() returns error.
      
      Fixes: 695093e3
      
       ("iommu/fsl: Freescale PAMU driver and iommu implementation.")
      Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
      Link: https://lore.kernel.org/r/20221121082022.19091-1-yuancan@huawei.com
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c9398323
    • Stefan Eichenberger's avatar
      rtc: snvs: Allow a time difference on clock register read · 4be1a8d8
      Stefan Eichenberger authored
      [ Upstream commit 0462681e ]
      
      On an iMX6ULL the following message appears when a wakealarm is set:
      
      echo 0 > /sys/class/rtc/rtc1/wakealarm
      rtc rtc1: Timeout trying to get valid LPSRT Counter read
      
      This does not always happen but is reproducible quite often (7 out of 10
      times). The problem appears because the iMX6ULL is not able to read the
      registers within one 32kHz clock cycle which is the base clock of the
      RTC. Therefore, this patch allows a difference of up to 320 cycles
      (10ms). 10ms was chosen to be big enough even on systems with less cpu
      power (e.g. iMX6ULL). According to the reference manual a difference is
      fine:
      - If the two consecutive reads are similar, the value is correct.
      The values have to be similar, not equal.
      
      Fixes: cd7f3a24
      
       ("rtc: snvs: Add timeouts to avoid kernel lockups")
      Reviewed-by: default avatarFrancesco Dolcini <francesco.dolcini@toradex.com>
      Signed-off-by: default avatarStefan Eichenberger <stefan.eichenberger@toradex.com>
      Signed-off-by: default avatarFrancesco Dolcini <francesco@dolcini.it>
      Link: https://lore.kernel.org/r/20221106115915.7930-1-francesco@dolcini.it
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4be1a8d8
    • Matt Redfearn's avatar
      include/uapi/linux/swab: Fix potentially missing __always_inline · 4e0b6364
      Matt Redfearn authored
      [ Upstream commit defbab27 ]
      
      Commit bc27fb68 ("include/uapi/linux/byteorder, swab: force inlining
      of some byteswap operations") added __always_inline to swab functions
      and commit 283d7573 ("uapi/linux/stddef.h: Provide __always_inline to
      userspace headers") added a definition of __always_inline for use in
      exported headers when the kernel's compiler.h is not available.
      
      However, since swab.h does not include stddef.h, if the header soup does
      not indirectly include it, the definition of __always_inline is missing,
      resulting in a compilation failure, which was observed compiling the
      perf tool using exported headers containing this commit:
      
      In file included from /usr/include/linux/byteorder/little_endian.h:12:0,
                       from /usr/include/asm/byteorder.h:14,
                       from tools/include/uapi/linux/perf_event.h:20,
                       from perf.h:8,
                       from builtin-bench.c:18:
      /usr/include/linux/swab.h:160:8: error: unknown type name `__always_inline'
       static __always_inline __u16 __swab16p(const __u16 *p)
      
      Fix this by replacing the inclusion of linux/compiler.h with
      linux/stddef.h to ensure that we pick up that definition if required,
      without relying on it's indirect inclusion. compiler.h is then included
      indirectly, via stddef.h.
      
      Fixes: 283d7573
      
       ("uapi/linux/stddef.h: Provide __always_inline to userspace headers")
      Signed-off-by: default avatarMatt Redfearn <matt.redfearn@mips.com>
      Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarPetr Vaněk <arkamar@atlas.cz>
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4e0b6364
    • Yuan Can's avatar
      HSI: omap_ssi_core: Fix error handling in ssi_init() · 7f43b9a9
      Yuan Can authored
      [ Upstream commit 3ffa9f71 ]
      
      The ssi_init() returns the platform_driver_register() directly without
      checking its return value, if platform_driver_register() failed, the
      ssi_pdriver is not unregistered.
      Fix by unregister ssi_pdriver when the last platform_driver_register()
      failed.
      
      Fixes: 0fae1989
      
       ("HSI: omap_ssi: built omap_ssi and omap_ssi_port into one module")
      Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f43b9a9
    • Zeng Heng's avatar
      power: supply: fix residue sysfs file in error handle route of __power_supply_register() · 29a57277
      Zeng Heng authored
      [ Upstream commit 5b79480c ]
      
      If device_add() succeeds, we should call device_del() when want to
      get rid of it, so move it into proper jump symbol.
      
      Otherwise, when __power_supply_register() returns fail and goto
      wakeup_init_failed to exit, there is still residue device file in sysfs.
      When attempt to probe device again, sysfs would complain as below:
      
      sysfs: cannot create duplicate filename '/devices/platform/i2c/i2c-0/0-001c/power_supply/adp5061'
      Call Trace:
       dump_stack_lvl+0x68/0x85
       sysfs_warn_dup.cold+0x1c/0x29
       sysfs_create_dir_ns+0x1b1/0x1d0
       kobject_add_internal+0x143/0x390
       kobject_add+0x108/0x170
      
      Fixes: 80c6463e
      
       ("power_supply: Fix Oops from NULL pointer dereference from wakeup_source_activate")
      Signed-off-by: default avatarZeng Heng <zengheng4@huawei.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      29a57277
    • Yang Yingliang's avatar
      HSI: omap_ssi_core: fix possible memory leak in ssi_probe() · 107eb675
      Yang Yingliang authored
      [ Upstream commit 1aff514e ]
      
      If ssi_add_controller() returns error, it should call hsi_put_controller()
      to give up the reference that was set in hsi_alloc_controller(), so that
      it can call hsi_controller_release() to free controller and ports that
      allocated in hsi_alloc_controller().
      
      Fixes: b209e047
      
       ("HSI: Introduce OMAP SSI driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      107eb675
    • Yang Yingliang's avatar
      HSI: omap_ssi_core: fix unbalanced pm_runtime_disable() · 8a502dfa
      Yang Yingliang authored
      [ Upstream commit f5181c35 ]
      
      In error label 'out1' path in ssi_probe(), the pm_runtime_enable()
      has not been called yet, so pm_runtime_disable() is not needed.
      
      Fixes: b209e047
      
       ("HSI: Introduce OMAP SSI driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8a502dfa
    • Christophe JAILLET's avatar
      fbdev: uvesafb: Fixes an error handling path in uvesafb_probe() · 8a62bc1c
      Christophe JAILLET authored
      [ Upstream commit a9437104 ]
      
      If an error occurs after a successful uvesafb_init_mtrr() call, it must be
      undone by a corresponding arch_phys_wc_del() call, as already done in the
      remove function.
      
      This has been added in the remove function in commit 63e28a7a
      ("uvesafb: Clean up MTRR code")
      
      Fixes: 8bdb3a2d
      
       ("uvesafb: the driver core")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8a62bc1c
    • Xiongfeng Wang's avatar
      fbdev: vermilion: decrease reference count in error path · 43838328
      Xiongfeng Wang authored
      [ Upstream commit 001f2cdb ]
      
      pci_get_device() will increase the reference count for the returned
      pci_dev. For the error path, we need to use pci_dev_put() to decrease
      the reference count.
      
      Fixes: dbe7e429
      
       ("vmlfb: framebuffer driver for Intel Vermilion Range")
      Signed-off-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      43838328
    • Shang XiaoJing's avatar
      fbdev: via: Fix error in via_core_init() · 5bf10c3b
      Shang XiaoJing authored
      [ Upstream commit 5886b130 ]
      
      via_core_init() won't exit the driver when pci_register_driver() failed.
      Exit the viafb-i2c and the viafb-gpio in failed path to prevent error.
      
      VIA Graphics Integration Chipset framebuffer 2.4 initializing
      Error: Driver 'viafb-i2c' is already registered, aborting...
      Error: Driver 'viafb-gpio' is already registered, aborting...
      
      Fixes: 7582eb9b
      
       ("viafb: Turn GPIO and i2c into proper platform devices")
      Signed-off-by: default avatarShang XiaoJing <shangxiaojing@huawei.com>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5bf10c3b
    • Yang Yingliang's avatar
      fbdev: pm2fb: fix missing pci_disable_device() · 0a71d047
      Yang Yingliang authored
      [ Upstream commit ed359a46 ]
      
      Add missing pci_disable_device() in error path of probe() and remove() path.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0a71d047
    • Andy Shevchenko's avatar
      fbdev: ssd1307fb: Drop optional dependency · c0cdb871
      Andy Shevchenko authored
      [ Upstream commit 025e3b50 ]
      
      Only a single out of three devices need a PWM, so from driver it's
      optional. Moreover it's a single driver in the entire kernel that
      currently selects PWM. Unfortunately this selection is a root cause
      of the circular dependencies when we want to enable optional PWM
      for some other drivers that select GPIOLIB.
      
      Fixes: a2ed00da
      
       ("drivers/video: add support for the Solomon SSD1307 OLED Controller")
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c0cdb871
    • 蒋家盛's avatar
      usb: storage: Add check for kcalloc · 0b8a070a
      蒋家盛 authored
      [ Upstream commit c35ca10f ]
      
      As kcalloc may return NULL pointer, the return value should
      be checked and return error if fails as same as the ones in
      alauda_read_map.
      
      Fixes: e80b0fad
      
       ("[PATCH] USB Storage: add alauda support")
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarJiasheng Jiang <jiasheng@iscas.ac.cn>
      Link: https://lore.kernel.org/r/20221208110058.12983-1-jiasheng@iscas.ac.cn
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0b8a070a