apparmor: Fix ref count leak in task_kill
[platform/kernel/linux-starfive.git] / lib / maple_tree.c
index 0e00a84..6846894 100644 (file)
@@ -5501,6 +5501,17 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
 
        mas_wr_end_piv(&wr_mas);
        node_size = mas_wr_new_end(&wr_mas);
+
+       /* Slot store, does not require additional nodes */
+       if (node_size == wr_mas.node_end) {
+               /* reuse node */
+               if (!mt_in_rcu(mas->tree))
+                       return 0;
+               /* shifting boundary */
+               if (wr_mas.offset_end - mas->offset == 1)
+                       return 0;
+       }
+
        if (node_size >= mt_slots[wr_mas.type]) {
                /* Split, worst case for now. */
                request = 1 + mas_mt_height(mas) * 2;
@@ -5627,7 +5638,7 @@ int mas_expected_entries(struct ma_state *mas, unsigned long nr_entries)
        /* Internal nodes */
        nr_nodes += DIV_ROUND_UP(nr_nodes, nonleaf_cap);
        /* Add working room for split (2 nodes) + new parents */
-       mas_node_count(mas, nr_nodes + 3);
+       mas_node_count_gfp(mas, nr_nodes + 3, GFP_KERNEL);
 
        /* Detect if allocations run out */
        mas->mas_flags |= MA_STATE_PREALLOC;