From patchwork Sat Oct 29 23:18:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 12787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1549130wru; Sat, 29 Oct 2022 16:21:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4jDRKMds9mqjKMchiXTShW8DtwOSu84QcGgBHODDoal9DjBW7OsJZHALEdhSqfw5WlH3Eq X-Received: by 2002:a17:906:cc48:b0:7a8:4a3b:11f7 with SMTP id mm8-20020a170906cc4800b007a84a3b11f7mr5880316ejb.388.1667085713893; Sat, 29 Oct 2022 16:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667085713; cv=none; d=google.com; s=arc-20160816; b=OwuEEwQpTVjHhrIktFmTjCRG4RUMZbAMZo4TEqGRlhTmbaMf0arbtWIMQI0VoXjcxx 5H7TQyWetIZBKFuiSaPjlgiqfWFzK79P2pfr1PU7mJYgMjyYjDD1Do8EJqTWeIfm3X8y 4n42gyaL/C1u/znKSqqRRtUly9RCJqHpa8cHHofaOJ9PqC4SUTwwQGmojhxTG0nKhBT8 Hhubbp1GY4gEkDwHpK/RCtL93gE5g7R0hcdbv2UoXCvHbCB+Js8YieOZlKI1ssuYhjvX 7S9bAXzCi4Z8akILA2YqdMWeBCmI12I/9N0/ASGiKXs60BvPehFKZKA2fVxMcRdKqU1g DJpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MQOuXgEd4uijladGhvf42ViTnATMp5s51KNIKFeH+uw=; b=PuDE9ULgHAQ5AnxltR9TUKKnifd6Q4lK6C+ym+xfXpeCnq7/gvzGBVjYCZ+8RTNm07 dHim15/PwuHxHaYDKO4dr1nSRS0dWjsFV8bEsUpwOhV4xSkk6B2V7oRHDDWHY1tsaDV/ z6kJ3hm2JnaJBTScLhv9L/k7gyPWd5IVmL5cunIhuDDOq00VwE5xk9/55iariUuRpqyi mc4jYAZW3fgwsiW0LF32YBC5Z8wCglSuQTl/AXajdu9b7fglfuP+nlOBj90lOKNjAZn2 SkiZUJM/TCZ5uZnph7xQrNl46ojnY1UkfRRUd8YZzH5rohuRxyxgdG3BlQ71avjRCwop oXJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=uRfPySHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa14-20020a1709076d0e00b00781f51771b6si2949735ejc.900.2022.10.29.16.21.29; Sat, 29 Oct 2022 16:21:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=uRfPySHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiJ2XTF (ORCPT + 99 others); Sat, 29 Oct 2022 19:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiJ2XSx (ORCPT ); Sat, 29 Oct 2022 19:18:53 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5BB2F00D; Sat, 29 Oct 2022 16:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=MQOuXgEd4uijladGhvf42ViTnATMp5s51KNIKFeH+uw=; b=uRfPySHb4xVQmQ1rA28MZQ3S9b d/25b4ehxWwsFjmU1ZCeQjljNYhdwuJHQmFqFrPVtCdCkmC5Fv1xMg/fGw6NXGfi92bewhpfVFSxN UHtTN332gAocwbX5+sQkAHscJNBQX7Bw8KFizNBcbC+IENqCVMwwaET1nSOyv+FYfjBrWO++VTbLi EFyOu0fMD0G9/BvcEJ6vZQRtWAnHV7oEF9qn+MI8SqAoifjYC/ZEHLM5ceWYwZ8YqNIqJyYdXHLYZ BPu9H+MnQT9xWs2mhqAX52f04PlTWl+vSFMfOLH2byDL25q+4k3wxe03HfksQ6T/ctXA7jK6NG10G vYysDuwQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oov6J-00FOKj-2W; Sat, 29 Oct 2022 23:18:51 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH 05/10] [elf][regset] simplify thread list handling in fill_note_info() Date: Sun, 30 Oct 2022 00:18:45 +0100 Message-Id: <20221029231850.3668437-5-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221029231850.3668437-1-viro@zeniv.linux.org.uk> References: <20221029231850.3668437-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748066069207344828?= X-GMAIL-MSGID: =?utf-8?q?1748066069207344828?= fill_note_info() iterates through the list of threads collected in mm->core_state->dumper, allocating a struct elf_thread_core_info instance for each and linking those into a list. We need the entry corresponding to current to be first in the resulting list, so the logics for list insertion is if it's for current or list is empty insert in the head else insert after the first element However, in mm->core_state->dumper the entry for current is guaranteed to be the first one. Which means that both parts of condition will be true on the first iteration and neither will be true on all subsequent ones. Taking the first iteration out of the loop simplifies things nicely... Signed-off-by: Al Viro --- fs/binfmt_elf.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 4190dafd2ec4..e990075fb43d 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1866,7 +1866,14 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, /* * Allocate a structure for each thread. */ - for (ct = &dump_task->signal->core_state->dumper; ct; ct = ct->next) { + info->thread = kzalloc(offsetof(struct elf_thread_core_info, + notes[info->thread_notes]), + GFP_KERNEL); + if (unlikely(!info->thread)) + return 0; + + info->thread->task = dump_task; + for (ct = dump_task->signal->core_state->dumper.next; ct; ct = ct->next) { t = kzalloc(offsetof(struct elf_thread_core_info, notes[info->thread_notes]), GFP_KERNEL); @@ -1874,17 +1881,8 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, return 0; t->task = ct->task; - if (ct->task == dump_task || !info->thread) { - t->next = info->thread; - info->thread = t; - } else { - /* - * Make sure to keep the original task at - * the head of the list. - */ - t->next = info->thread->next; - info->thread->next = t; - } + t->next = info->thread->next; + info->thread->next = t; } /*