imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,48 +1,48 @@
 asmlinkage void secondary_start_kernel(void) {
   struct mm_struct *mm = &init_mm;
   unsigned int cpu = smp_processor_id();
   /*
    * All kernel threads share the same mm context; grab a
    * reference and switch to it.
    */
   atomic_inc(&mm->mm_users);
-  atomic_inc(&mm->mm_count);
+  mmgrab(mm);
   current->active_mm = mm;
   cpumask_set_cpu(cpu, mm_cpumask(mm));
   enter_lazy_tlb(mm, current);
   local_flush_tlb_all();
   /*
    * TODO: Some day it might be useful for each Linux CPU to
    * have its own TBI structure. That would allow each Linux CPU
    * to run different interrupt handlers for the same IRQ
    * number.
    *
    * For now, simply copying the pointer to the boot CPU's TBI
    * structure is sufficient because we always want to run the
    * same interrupt handler whatever CPU takes the interrupt.
    */
   per_cpu(pTBI, cpu) = __TBI(TBID_ISTAT_BIT);
   if (!per_cpu(pTBI, cpu)) panic("No TBI found!");
   per_cpu_trap_init(cpu);
   irq_ctx_init(cpu);
   preempt_disable();
   setup_priv();
   notify_cpu_starting(cpu);
   pr_info("CPU%u (thread %u): Booted secondary processor\n", cpu, cpu_2_hwthread_id[cpu]);
   calibrate_delay();
   smp_store_cpu_info(cpu);
   /*
    * OK, now it's safe to let the boot CPU continue
    */
   set_cpu_online(cpu, true);
   complete(&cpu_running);
   /*
    * Enable local interrupts.
    */
   tbi_startup_interrupt(TBID_SIGNUM_TRT);
   local_irq_enable();
   /*
    * OK, it's off to the idle thread for us
    */
   cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,17 +1,17 @@
 void use_mm(struct mm_struct *mm) {
   struct mm_struct *active_mm;
   struct task_struct *tsk = current;
   task_lock(tsk);
   active_mm = tsk->active_mm;
   if (active_mm != mm) {
-    atomic_inc(&mm->mm_count);
+    mmgrab(mm);
     tsk->active_mm = mm;
   }
   tsk->mm = mm;
   switch_mm(active_mm, mm, tsk);
   task_unlock(tsk);
 #ifdef finish_arch_post_lock_switch
   finish_arch_post_lock_switch();
 #endif
   if (active_mm != mm) mmdrop(active_mm);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,41 +1,41 @@
 static int do_mmu_notifier_register(struct mmu_notifier *mn, struct mm_struct *mm, int take_mmap_sem) {
   struct mmu_notifier_mm *mmu_notifier_mm;
   int ret;
   BUG_ON(atomic_read(&mm->mm_users) <= 0);
   /*
    * Verify that mmu_notifier_init() already run and the global srcu is
    * initialized.
    */
   BUG_ON(!srcu.per_cpu_ref);
   ret = -ENOMEM;
   mmu_notifier_mm = kmalloc(sizeof(struct mmu_notifier_mm), GFP_KERNEL);
   if (unlikely(!mmu_notifier_mm)) goto out;
   if (take_mmap_sem) down_write(&mm->mmap_sem);
   ret = mm_take_all_locks(mm);
   if (unlikely(ret)) goto out_clean;
   if (!mm_has_notifiers(mm)) {
     INIT_HLIST_HEAD(&mmu_notifier_mm->list);
     spin_lock_init(&mmu_notifier_mm->lock);
     mm->mmu_notifier_mm = mmu_notifier_mm;
     mmu_notifier_mm = NULL;
   }
-  atomic_inc(&mm->mm_count);
+  mmgrab(mm);
   /*
    * Serialize the update against mmu_notifier_unregister. A
    * side note: mmu_notifier_release can't run concurrently with
    * us because we hold the mm_users pin (either implicitly as
    * current->mm or explicitly with get_task_mm() or similar).
    * We can't race against any other mmu notifier method either
    * thanks to mm_take_all_locks().
    */
   spin_lock(&mm->mmu_notifier_mm->lock);
   hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list);
   spin_unlock(&mm->mmu_notifier_mm->lock);
   mm_drop_all_locks(mm);
 out_clean:
   if (take_mmap_sem) up_write(&mm->mmap_sem);
   kfree(mmu_notifier_mm);
 out:
   BUG_ON(atomic_read(&mm->mm_users) <= 0);
   return ret;
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,33 +1,33 @@
 static void __init smp_cpu_init(void) {
   unsigned long flags;
   int cpu_id = smp_processor_id();
   u16 tmp16;
   if (test_and_set_bit(cpu_id, &cpu_initialized)) {
     printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id);
     for (;;)
       local_irq_enable();
   }
   printk(KERN_INFO "Initializing CPU#%d\n", cpu_id);
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   BUG_ON(current->mm);
   enter_lazy_tlb(&init_mm, current);
   /* Force FPU initialization */
   clear_using_fpu(current);
   GxICR(CALL_FUNC_SINGLE_IPI) = CALL_FUNCTION_GxICR_LV | GxICR_DETECT;
   mn10300_ipi_enable(CALL_FUNC_SINGLE_IPI);
   GxICR(LOCAL_TIMER_IPI) = LOCAL_TIMER_GxICR_LV | GxICR_DETECT;
   mn10300_ipi_enable(LOCAL_TIMER_IPI);
   GxICR(RESCHEDULE_IPI) = RESCHEDULE_GxICR_LV | GxICR_DETECT;
   mn10300_ipi_enable(RESCHEDULE_IPI);
 #ifdef CONFIG_MN10300_CACHE_ENABLED
   GxICR(FLUSH_CACHE_IPI) = FLUSH_CACHE_GxICR_LV | GxICR_DETECT;
   mn10300_ipi_enable(FLUSH_CACHE_IPI);
 #endif
   mn10300_ipi_shutdown(SMP_BOOT_IRQ);
   /* Set up the non-maskable call function IPI */
   flags = arch_local_cli_save();
   GxICR(CALL_FUNCTION_NMI_IPI) = GxICR_NMI | GxICR_ENABLE | GxICR_DETECT;
   tmp16 = GxICR(CALL_FUNCTION_NMI_IPI);
   arch_local_irq_restore(flags);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,16 +1,16 @@
 static void mark_oom_victim(struct task_struct *tsk) {
   struct mm_struct *mm = tsk->mm;
   WARN_ON(oom_killer_disabled);
   /* OOM killer might race with memcg OOM */
   if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE)) return;
   /* oom_mm is bound to the signal struct life time. */
-  if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) atomic_inc(&tsk->signal->oom_mm->mm_count);
+  if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) mmgrab(tsk->signal->oom_mm);
   /*
    * Make sure that the task is woken up from uninterruptible sleep
    * if it is frozen because OOM killer wouldn't be able to free
    * any memory and livelock. freezing_slow_path will tell the freezer
    * that TIF_MEMDIE tasks should be ignored.
    */
   __thaw_task(tsk);
   atomic_inc(&oom_victims);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,24 +1,24 @@
 static void __init smp_cpu_init(int cpunum) {
   extern int init_per_cpu(int);       /* arch/parisc/kernel/processor.c */
   extern void init_IRQ(void);         /* arch/parisc/kernel/irq.c */
   extern void start_cpu_itimer(void); /* arch/parisc/kernel/time.c */
   /* Set modes and Enable floating point coprocessor */
   (void)init_per_cpu(cpunum);
   disable_sr_hashing();
   mb();
   /* Well, support 2.4 linux scheme as well. */
   if (cpu_online(cpunum)) {
     extern void machine_halt(void); /* arch/parisc.../process.c */
     printk(KERN_CRIT "CPU#%d already initialized!\n", cpunum);
     machine_halt();
   }
   notify_cpu_starting(cpunum);
   set_cpu_online(cpunum, true);
   /* Initialise the idle task for this CPU */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   BUG_ON(current->mm);
   enter_lazy_tlb(&init_mm, current);
   init_IRQ(); /* make sure no IRQs are enabled or pending */
   start_cpu_itimer();
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,39 +1,39 @@
 void start_secondary(void *unused) {
   unsigned int cpu = smp_processor_id();
   int i, base;
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   smp_store_cpu_info(cpu);
   set_dec(tb_ticks_per_jiffy);
   preempt_disable();
   cpu_callin_map[cpu] = 1;
   if (smp_ops->setup_cpu) smp_ops->setup_cpu(cpu);
   if (smp_ops->take_timebase) smp_ops->take_timebase();
   secondary_cpu_time_init();
 #ifdef CONFIG_PPC64
   if (system_state == SYSTEM_RUNNING) vdso_data->processorCount++;
   vdso_getcpu_init();
 #endif
   /* Update sibling maps */
   base = cpu_first_thread_sibling(cpu);
   for (i = 0; i < threads_per_core; i++) {
     if (cpu_is_offline(base + i) && (cpu != base + i)) continue;
     cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
     cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
     /* cpu_core_map should be a superset of
      * cpu_sibling_map even if we don't have cache
      * information, so update the former here, too.
      */
     cpumask_set_cpu(cpu, cpu_core_mask(base + i));
     cpumask_set_cpu(base + i, cpu_core_mask(cpu));
   }
   traverse_core_siblings(cpu, true);
   set_numa_node(numa_cpu_lookup_table[cpu]);
   set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
   smp_wmb();
   notify_cpu_starting(cpu);
   set_cpu_online(cpu, true);
   local_irq_enable();
   cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
   BUG();
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,9 +1,9 @@
 void cpu_init(void) {
   struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
   get_cpu_id(id);
   if (machine_has_cpu_mhz) update_cpu_mhz(NULL);
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   BUG_ON(current->mm);
   enter_lazy_tlb(&init_mm, current);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,22 +1,22 @@
 void __init cpu_init(void) {
   int cpu_id = smp_processor_id();
   if (test_and_set_bit(cpu_id, &cpu_initialized)) {
     printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id);
     for (;;)
       local_irq_enable();
   }
   printk(KERN_INFO "Initializing CPU#%d\n", cpu_id);
   /* Set up and load the per-CPU TSS and LDT */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   if (current->mm) BUG();
   /* Force FPU initialization */
   current_thread_info()->status = 0;
   clear_used_math();
 #ifdef CONFIG_MMU
   /* Set up MMU */
   init_mmu();
 #endif
   /* Set up ICUIMASK */
   outl(0x00070000, M32R_ICU_IMASK_PORTL); /* imask=111 */
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,30 +1,30 @@
 void smp_callin(void) {
   int cpuid = hard_smp_processor_id();
   __local_per_cpu_offset = __per_cpu_offset(cpuid);
   if (tlb_type == hypervisor) sun4v_ktsb_register();
   __flush_tlb_all();
   setup_sparc64_timer();
   if (cheetah_pcache_forced_on) cheetah_enable_pcache();
   callin_flag = 1;
   __asm__ __volatile__("membar #Sync\n\t"
                        "flush  %%g6"
                        :
                        :
                        : "memory");
   /* Clear this or we will die instantly when we
    * schedule back to this idler...
    */
   current_thread_info()->new_child = 0;
   /* Attach to the address space of init_task. */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   /* inform the notifiers about the new cpu */
   notify_cpu_starting(cpuid);
   while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
     rmb();
   set_cpu_online(cpuid, true);
   /* idle thread is expected to have preempt disabled */
   preempt_disable();
   local_irq_enable();
   cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,31 +1,31 @@
 void secondary_start_kernel(void) {
   struct mm_struct *mm = &init_mm;
   unsigned int cpu = smp_processor_id();
   init_mmu();
 #ifdef CONFIG_DEBUG_KERNEL
   if (boot_secondary_processors == 0) {
     pr_debug("%s: boot_secondary_processors:%d; Hanging cpu:%d\n", __func__, boot_secondary_processors, cpu);
     for (;;)
       __asm__ __volatile__("waiti " __stringify(LOCKLEVEL));
   }
   pr_debug("%s: boot_secondary_processors:%d; Booting cpu:%d\n", __func__, boot_secondary_processors, cpu);
 #endif
   /* Init EXCSAVE1 */
   secondary_trap_init();
   /* All kernel threads share the same mm context. */
   atomic_inc(&mm->mm_users);
-  atomic_inc(&mm->mm_count);
+  mmgrab(mm);
   current->active_mm = mm;
   cpumask_set_cpu(cpu, mm_cpumask(mm));
   enter_lazy_tlb(mm, current);
   preempt_disable();
   trace_hardirqs_off();
   calibrate_delay();
   notify_cpu_starting(cpu);
   secondary_init_irq();
   local_timer_setup(cpu);
   set_cpu_online(cpu, true);
   local_irq_enable();
   complete(&cpu_running);
   cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,30 +1,30 @@
 static void start_secondary(void) {
   int cpuid;
   preempt_disable();
   cpuid = smp_processor_id();
   /* Set our thread pointer appropriately. */
   set_my_cpu_offset(__per_cpu_offset[cpuid]);
   /*
    * In large machines even this will slow us down, since we
    * will be contending for for the printk spinlock.
    */
   /* printk(KERN_DEBUG "Initializing CPU#%d\n", cpuid); */
   /* Initialize the current asid for our first page table. */
   __this_cpu_write(current_asid, min_asid);
   /* Set up this thread as another owner of the init_mm */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   if (current->mm) BUG();
   enter_lazy_tlb(&init_mm, current);
   /* Allow hypervisor messages to be received */
   init_messaging();
   local_irq_enable();
   /* Indicate that we're ready to come up. */
   /* Must not do this before we're ready to receive messages */
   if (cpumask_test_and_set_cpu(cpuid, &cpu_started)) {
     pr_warn("CPU#%d already started!\n", cpuid);
     for (;;)
       local_irq_enable();
   }
   smp_nap();
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,31 +1,31 @@
 void sun4d_cpu_pre_online(void *arg) {
   unsigned long flags;
   int cpuid;
   cpuid = hard_smp_processor_id();
   /* Unblock the master CPU _only_ when the scheduler state
    * of all secondary CPUs will be up-to-date, so after
    * the SMP initialization the master will be just allowed
    * to call the scheduler code.
    */
   sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
   local_ops->cache_all();
   local_ops->tlb_all();
   while ((unsigned long)current_set[cpuid] < PAGE_OFFSET)
     barrier();
   while (current_set[cpuid]->cpu != cpuid)
     barrier();
   /* Fix idle thread fields. */
   __asm__ __volatile__("ld [%0], %%g6\n\t" : : "r"(&current_set[cpuid]) : "memory" /* paranoid */);
   cpu_leds[cpuid] = 0x9;
   show_leds(cpuid);
   /* Attach to the address space of init_task. */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   local_ops->cache_all();
   local_ops->tlb_all();
   while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
     barrier();
   spin_lock_irqsave(&sun4d_imsk_lock, flags);
   cc_set_imsk(cc_get_imsk() & ~0x4000); /* Allow PIL 14 as well */
   spin_unlock_irqrestore(&sun4d_imsk_lock, flags);
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,19 +1,19 @@
 void sun4m_cpu_pre_online(void *arg) {
   int cpuid = hard_smp_processor_id();
   /* Allow master to continue. The master will then give us the
    * go-ahead by setting the smp_commenced_mask and will wait without
    * timeouts until our setup is completed fully (signified by
    * our bit being set in the cpu_online_mask).
    */
   swap_ulong(&cpu_callin_map[cpuid], 1);
   /* XXX: What's up with all the flushes? */
   local_ops->cache_all();
   local_ops->tlb_all();
   /* Fix idle thread fields. */
   __asm__ __volatile__("ld [%0], %%g6\n\t" : : "r"(&current_set[cpuid]) : "memory" /* paranoid */);
   /* Attach to the address space of init_task. */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
     mb();
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,11 +1,11 @@
 void trap_init(void) {
   extern void thread_info_offsets_are_bolixed_pete(void);
   /* Force linker to barf if mismatched */
   if (TI_UWINMASK != offsetof(struct thread_info, uwinmask) || TI_TASK != offsetof(struct thread_info, task) || TI_FLAGS != offsetof(struct thread_info, flags) || TI_CPU != offsetof(struct thread_info, cpu) || TI_PREEMPT != offsetof(struct thread_info, preempt_count) || TI_SOFTIRQ != offsetof(struct thread_info, softirq_count) || TI_HARDIRQ != offsetof(struct thread_info, hardirq_count) || TI_KSP != offsetof(struct thread_info, ksp) || TI_KPC != offsetof(struct thread_info, kpc) || TI_KPSR != offsetof(struct thread_info, kpsr) || TI_KWIM != offsetof(struct thread_info, kwim) || TI_REG_WINDOW != offsetof(struct thread_info, reg_window) || TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) || TI_W_SAVED != offsetof(struct thread_info, w_saved)) thread_info_offsets_are_bolixed_pete();
   /* Attach to the address space of init_task. */
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   /* NOTE: Other cpus have this done as they are started
    *       up on SMP.
    */
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,35 +1,35 @@
 void __init trap_init(void) {
   int i;
   pgd_current = (unsigned long)init_mm.pgd;
   /* DEBUG EXCEPTION */
   memcpy((void *)DEBUG_VECTOR_BASE_ADDR, &debug_exception_vector, DEBUG_VECTOR_SIZE);
   /* NMI EXCEPTION */
   memcpy((void *)GENERAL_VECTOR_BASE_ADDR, &general_exception_vector, GENERAL_VECTOR_SIZE);
   /*
    * Initialise exception handlers
    */
   for (i = 0; i <= 31; i++)
     set_except_vector(i, handle_reserved);
   set_except_vector(1, handle_nmi);
   set_except_vector(2, handle_adelinsn);
   set_except_vector(3, handle_tlb_refill);
   set_except_vector(4, handle_tlb_invaild);
   set_except_vector(5, handle_ibe);
   set_except_vector(6, handle_pel);
   set_except_vector(7, handle_sys);
   set_except_vector(8, handle_ccu);
   set_except_vector(9, handle_ri);
   set_except_vector(10, handle_tr);
   set_except_vector(11, handle_adedata);
   set_except_vector(12, handle_adedata);
   set_except_vector(13, handle_tlb_refill);
   set_except_vector(14, handle_tlb_invaild);
   set_except_vector(15, handle_mod);
   set_except_vector(16, handle_cee);
   set_except_vector(17, handle_cpe);
   set_except_vector(18, handle_dbe);
   flush_icache_range(DEBUG_VECTOR_BASE_ADDR, IRQ_VECTOR_BASE_ADDR);
-  atomic_inc(&init_mm.mm_count);
+  mmgrab(&init_mm);
   current->active_mm = &init_mm;
   cpu_cache_init();
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm.mm_count);
+       mmgrab(&init_mm);
--- initial
+++ final
@@ -1,36 +1,36 @@
 int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs) {
   struct userfaultfd_ctx *ctx = NULL, *octx;
   struct userfaultfd_fork_ctx *fctx;
   octx = vma->vm_userfaultfd_ctx.ctx;
   if (!octx || !(octx->features & UFFD_FEATURE_EVENT_FORK)) {
     vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
     vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING);
     return 0;
   }
   list_for_each_entry(fctx, fcs, list) if (fctx->orig == octx) {
     ctx = fctx->new;
     break;
   }
   if (!ctx) {
     fctx = kmalloc(sizeof(*fctx), GFP_KERNEL);
     if (!fctx) return -ENOMEM;
     ctx = kmem_cache_alloc(userfaultfd_ctx_cachep, GFP_KERNEL);
     if (!ctx) {
       kfree(fctx);
       return -ENOMEM;
     }
     atomic_set(&ctx->refcount, 1);
     ctx->flags = octx->flags;
     ctx->state = UFFD_STATE_RUNNING;
     ctx->features = octx->features;
     ctx->released = false;
     ctx->mm = vma->vm_mm;
-    atomic_inc(&ctx->mm->mm_count);
+    mmgrab(ctx->mm);
     userfaultfd_ctx_get(octx);
     fctx->orig = octx;
     fctx->new = ctx;
     list_add_tail(&fctx->list, fcs);
   }
   vma->vm_userfaultfd_ctx.ctx = ctx;
   return 0;
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,28 +1,28 @@
 static struct file *userfaultfd_file_create(int flags) {
   struct file *file;
   struct userfaultfd_ctx *ctx;
   BUG_ON(!current->mm);
   /* Check the UFFD_* constants for consistency.  */
   BUILD_BUG_ON(UFFD_CLOEXEC != O_CLOEXEC);
   BUILD_BUG_ON(UFFD_NONBLOCK != O_NONBLOCK);
   file = ERR_PTR(-EINVAL);
   if (flags & ~UFFD_SHARED_FCNTL_FLAGS) goto out;
   file = ERR_PTR(-ENOMEM);
   ctx = kmem_cache_alloc(userfaultfd_ctx_cachep, GFP_KERNEL);
   if (!ctx) goto out;
   atomic_set(&ctx->refcount, 1);
   ctx->flags = flags;
   ctx->features = 0;
   ctx->state = UFFD_STATE_WAIT_API;
   ctx->released = false;
   ctx->mm = current->mm;
   /* prevent the mm struct to be freed */
-  atomic_inc(&ctx->mm->mm_count);
+  mmgrab(ctx->mm);
   file = anon_inode_getfile("[userfaultfd]", &userfaultfd_fops, ctx, O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
   if (IS_ERR(file)) {
     mmdrop(ctx->mm);
     kmem_cache_free(userfaultfd_ctx_cachep, ctx);
   }
 out:
   return file;
 }<sep>@@
expression init_mm;
@@
-       atomic_inc(&init_mm->mm_count);
+       mmgrab(init_mm);
--- initial
+++ final
@@ -1,20 +1,18 @@
 int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np) {
   struct drm_encoder *encoder;
   struct drm_bridge *bridge;
   int ret = 0;
   encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
   if (encoder == NULL) return -ENOMEM;
   /* Locate drm bridge from the hdmi encoder DT node */
   bridge = of_drm_find_bridge(np);
   if (!bridge) return -EPROBE_DEFER;
   encoder->possible_crtcs = 1;
   encoder->possible_clones = 0;
   ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs, DRM_MODE_ENCODER_TMDS, NULL);
   if (ret) return ret;
   /* Link drm_bridge to encoder */
-  bridge->encoder = encoder;
-  encoder->bridge = bridge;
-  ret = drm_bridge_attach(drm, bridge);
+  ret = drm_bridge_attach(encoder, bridge, NULL);
   if (ret) drm_encoder_cleanup(encoder);
   return ret;
 }<sep>@@
expression br,enc,ret;
@@

-       br->encoder = enc;
	...
-       enc->bridge = br;
	...
-       ret = drm_bridge_attach(drm, br);
+       ret = drm_bridge_attach(enc, br, NULL);
--- initial
+++ final
@@ -1,31 +1,29 @@
 static int imx_pd_register(struct drm_device *drm, struct imx_parallel_display *imxpd) {
   struct drm_encoder *encoder = &imxpd->encoder;
   int ret;
   ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node);
   if (ret) return ret;
   /* set the connector's dpms to OFF so that
    * drm_helper_connector_dpms() won't return
    * immediately since the current state is ON
    * at this point.
    */
   imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
   drm_encoder_helper_add(encoder, &imx_pd_encoder_helper_funcs);
   drm_encoder_init(drm, encoder, &imx_pd_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL);
   if (!imxpd->bridge) {
     drm_connector_helper_add(&imxpd->connector, &imx_pd_connector_helper_funcs);
     drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs, DRM_MODE_CONNECTOR_VGA);
   }
   if (imxpd->panel) drm_panel_attach(imxpd->panel, &imxpd->connector);
   if (imxpd->bridge) {
-    imxpd->bridge->encoder = encoder;
-    encoder->bridge = imxpd->bridge;
-    ret = drm_bridge_attach(drm, imxpd->bridge);
+    ret = drm_bridge_attach(encoder, imxpd->bridge, NULL);
     if (ret < 0) {
       dev_err(imxpd->dev, "failed to attach bridge: %d\n", ret);
       return ret;
     }
   } else {
     drm_mode_connector_attach_encoder(&imxpd->connector, encoder);
   }
   return 0;
 }<sep>@@
expression br,enc,ret;
@@

-       br->encoder = enc;
	...
-       enc->bridge = br;
	...
-       ret = drm_bridge_attach(drm, br);
+       ret = drm_bridge_attach(enc, br, NULL);