]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/hns: drop dead empty check in setup_root_hem()
authorMaoyi Xie <maoyixie.tju@gmail.com>
Tue, 26 May 2026 05:46:53 +0000 (13:46 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 3 Jun 2026 18:04:40 +0000 (15:04 -0300)
setup_root_hem() reads the first entry of head->root and checks
the returned pointer against NULL:

    root_hem = list_first_entry(&head->root,
                                struct hns_roce_hem_item, list);
    if (!root_hem)
        return -ENOMEM;

list_first_entry() never returns NULL. On an empty list it returns
container_of(head, ..., list), a non-NULL garbage pointer that
aliases the head. So the check is dead.

The only caller adds an entry to head.root right before invoking
setup_root_hem():

    list_add(&root_hem->list, &head.root);
    ret = setup_root_hem(..., &head, ...);

So head.root is guaranteed non-empty on entry. Drop the check.

Link: https://patch.msgid.link/r/20260526054653.2054800-1-maoyixie.tju@gmail.com
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/hns/hns_roce_hem.c

index ccb40f8a48b7260b9f9b17e208fef8b5a0173518..7041a8e9134b220b428d37a51bd444a87d25610e 100644 (file)
@@ -1269,8 +1269,6 @@ setup_root_hem(struct hns_roce_dev *hr_dev, struct hns_roce_hem_list *hem_list,
 
        root_hem = list_first_entry(&head->root,
                                    struct hns_roce_hem_item, list);
-       if (!root_hem)
-               return -ENOMEM;
 
        total = 0;
        for (i = 0; i < region_cnt && total <= max_ba_num; i++) {