From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A35133955F1 for ; Sun, 24 May 2026 16:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779641897; cv=none; b=Ck3gYZEah8Cm/El5yChUf1udV+R6whzE8/No5J2EM80ZJL2GELgVchb8VLK4/28znWS7Lsgc7nymcT5qLDZ9XXrS9Qb7R2G6BDzFmdLuNigpKXUqIKoF9P7dtkhH/Qiw4Ckjn/lXOL0QLHAoYvgGSwrW8NIL2SvNROoQEYMvTps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779641897; c=relaxed/simple; bh=F/LG87ymRdVrDmc3k6wNOwla5PWNTmNyt+0M/WxwHgE=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=QQfZ/p9ybqHAqDMADl4Vkch46SPd0cRiZI+eGEJ4YKzP+p5DIqRN/1fnjapfXnfi8iI8Y1BsLH8qMMBbCtBI6LAMpD5GUrXz0e0wP9rU1TayGNJ6KvYh7dTlM3Xl1n4q9R25n5pytqz2oG3cWKc0ZKs7BIhjiFx0pARzqiEn16k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=N3AR3VZS; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N3AR3VZS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779641894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=uF5Ltar24PxhfK2RJK52qj/LVT6BFAvA6BDox8hw3ZE=; b=N3AR3VZSIRbyChHx1QhTvFeYpWD+fH1HoIvYOLDcfdt+1ialNby64uxFytBLcmSSm5FBuz oz1iO0RIAfL6o3mmsr/WHs0MKYL3A5ZnZLJc2309RUHbCinHCZ3N5i2GPrNz3fXH8lDd1M UpglhEMVQ5sgxmFtqMbwIqbYHT483ns= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-zju1gaudOq27gyZFRB49-w-1; Sun, 24 May 2026 12:58:08 -0400 X-MC-Unique: zju1gaudOq27gyZFRB49-w-1 X-Mimecast-MFC-AGG-ID: zju1gaudOq27gyZFRB49-w_1779641886 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E01551956094; Sun, 24 May 2026 16:58:05 +0000 (UTC) Received: from fedora (unknown [10.44.48.14]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id D8272300019F; Sun, 24 May 2026 16:58:00 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 24 May 2026 18:58:05 +0200 (CEST) Date: Sun, 24 May 2026 18:57:59 +0200 From: Oleg Nesterov To: Alistair Popple , Andrew Morton , Byungchul Park , David Hildenbrand , Gregory Price , Joshua Hahn , Matthew Brost , Rakie Kim , Ying Huang , Zi Yan Cc: Jann Horn , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mm/mempolicy: kernel_migrate_pages: simplify the usage of put_task_struct() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 kernel_migrate_pages() calls put_task_struct() twice; this complicates the code. Move put_task_struct() to the unified exit path. This also allows us to move the "out_put" label up and avoid another goto. Signed-off-by: Oleg Nesterov --- mm/mempolicy.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4e4421b22b59..4326dff16aa6 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1922,25 +1922,20 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, goto out_put; mm = get_task_mm(task); - put_task_struct(task); - if (!mm) { err = -EINVAL; - goto out; + goto out_put; } err = do_migrate_pages(mm, old, new, capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE); mmput(mm); +out_put: + put_task_struct(task); out: NODEMASK_SCRATCH_FREE(scratch); - return err; - -out_put: - put_task_struct(task); - goto out; } SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode, -- 2.52.0