Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1260700lqs; Sat, 15 Jun 2024 01:06:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVCk/owGCBLI52ukk3LQIhxnGNnGLtBGBMMVTSWgRl65eZcJ2TgSu0BiwJbd12kVGOJa+jRMISaTC4co405+t6Rj0wWnbCn4U/Tv8hfbQ== X-Google-Smtp-Source: AGHT+IFsfjntSQDgb9HOXSoFnluJQRMmLqpD8u3NRYjVnHp7Z+BwmsWf1YWssuJl7x3/hR1xpSDb X-Received: by 2002:a05:6a20:a123:b0:1af:cfca:e515 with SMTP id adf61e73a8af0-1bae7d8538dmr6629857637.12.1718438782454; Sat, 15 Jun 2024 01:06:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718438782; cv=pass; d=google.com; s=arc-20160816; b=Ah1ybQHv0jD5p2zQ/ejaENX/PmkRgydV1iA+GKl1LYGyDkGmMQEHdADgy54fCMibl6 ZQv9EpEtQbGO+K4SQsSwppRFz/p76vGx83zRbjVJ+LBWz0pSru3pMvqhoHdhXkwsvP2U Ttiq8unzL4WobeD8GIOQvhVRVI6kLdTdZuMD1liwv88QMKvr68hbvxYkyAXF2rKs5BQR a/2JDus5NcNq7vioFHAhqodqdx5p5jTKRbCFtfuvGwYqxF0/7mJs6y+fdeixIFOb44qs Bjw9DUMyKj88ZqPC+7b87BosLfmCGwzXte7UsN5WQ/IImjxE5LlNGcvL7VsizmXJmf97 +oSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=MdyxUW6NkxrNCnB0kdfx1RBEyIEBoL4btDkrUZccOmA=; fh=Etcx+erCnVq6NRrVl32D57Fu54vDIh6Nvh1tzj67TLo=; b=zzIo+1ylofJftDpbetuFfyzR7sV9hVccep3lCoQaF86W5Nx6cIe+Mhiu6aUeHYJRIA tzPmUc9wUXbUXHIdjni85UzX907snvCaLxyXxTiCe62e1sogA6DDCGSOOnesHel7IqeK KilvQ4ai5QFT/Hrukg1gLcRGr7WMOiUkhtHG6Td84RaMwyNjbFZgl968rMXq3SWxWGno MxH/cECwSkf/t5X7ZKh4TWeoEoqNDfE+scAhoZhhQzGdPmis2nwWCkWs2vNEj+57kdLZ CGi98ZhCGkAiPMUJAU3nFkebwUwEyWc+p5PAXJV64rc1BTK727MDS9ojqa5a4Wdh9XzL uvCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-215759-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f855f2b358si48202185ad.621.2024.06.15.01.06.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 01:06:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215759-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-215759-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 199F7284C20 for ; Sat, 15 Jun 2024 08:06:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CC4E1803E; Sat, 15 Jun 2024 08:06:17 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 81E33171B0 for ; Sat, 15 Jun 2024 08:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718438776; cv=none; b=gYdn5uhA+rb/l1GYMDdJUN5/KI6gj7tTqtguQegEUhJ9HjrgsWWTIQkaTdHnKdz6GJwxgkHoZXF6aIZCHiAo89JQyTul4Sar7MxEueZOyGHGxh25+yWXvaa3fS2Ct7pfVAqpZynmSgMrB7f+s7KcclOSdkjjq0vfOVDoSrBXqrY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718438776; c=relaxed/simple; bh=Sl6y5vSpvo/TDY1A0GnSjLx1TQ3HOsv/EHlKZf9iTdI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=EqSfqW4h6N9WR8bauusInt0yanxTj7CHqSzJdQ0THX0uGJ+mt5QTedgLxRfd9U2+N3V4Uvjqw6TAvCOkLrLv1AjzIt7+gnoeBUo/IibT/TJMYlsdbcMODbfWHRiXz2ZbA4ot0CFTusOtlM0bURs9b0NC4mfURl8NJOataDMo2iw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4W1TBb4mTPzwSS0; Sat, 15 Jun 2024 16:01:59 +0800 (CST) Received: from dggpeml500012.china.huawei.com (unknown [7.185.36.15]) by mail.maildlp.com (Postfix) with ESMTPS id 4F40B180064; Sat, 15 Jun 2024 16:06:09 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Sat, 15 Jun 2024 16:06:09 +0800 From: Zheng Yejian To: , , , , , CC: , Subject: [PATCH] kallsyms: Simply clean get_symbol_pos() Date: Sat, 15 Jun 2024 16:06:43 +0800 Message-ID: <20240615080643.3865878-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500012.china.huawei.com (7.185.36.15) 'symbol_end' is just for calculating 'symbolsize', so if 'symbolsize' is NULL, there is no need to find 'symbol_end'. Besides, if 'offset' is also NULL, there is even no need to assign to 'symbol_start'. So just do cleanup. Signed-off-by: Zheng Yejian --- kernel/kallsyms.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 22ea19a36e6e..fe6a248d629a 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -322,8 +322,8 @@ static unsigned long get_symbol_pos(unsigned long addr, unsigned long *symbolsize, unsigned long *offset) { - unsigned long symbol_start = 0, symbol_end = 0; - unsigned long i, low, high, mid; + unsigned long symbol_start; + unsigned long low, high, mid; /* Do a binary search on the sorted kallsyms_addresses array. */ low = 0; @@ -344,28 +344,35 @@ static unsigned long get_symbol_pos(unsigned long addr, while (low && kallsyms_sym_address(low-1) == kallsyms_sym_address(low)) --low; + if (unlikely(!symbolsize && !offset)) + return low; + symbol_start = kallsyms_sym_address(low); - /* Search for next non-aliased symbol. */ - for (i = low + 1; i < kallsyms_num_syms; i++) { - if (kallsyms_sym_address(i) > symbol_start) { - symbol_end = kallsyms_sym_address(i); - break; + if (symbolsize) { + unsigned long symbol_end = 0; + unsigned long i; + + /* Search for next non-aliased symbol. */ + for (i = low + 1; i < kallsyms_num_syms; i++) { + if (kallsyms_sym_address(i) > symbol_start) { + symbol_end = kallsyms_sym_address(i); + break; + } } - } - /* If we found no next symbol, we use the end of the section. */ - if (!symbol_end) { - if (is_kernel_inittext(addr)) - symbol_end = (unsigned long)_einittext; - else if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) - symbol_end = (unsigned long)_end; - else - symbol_end = (unsigned long)_etext; - } + /* If we found no next symbol, we use the end of the section. */ + if (!symbol_end) { + if (is_kernel_inittext(addr)) + symbol_end = (unsigned long)_einittext; + else if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) + symbol_end = (unsigned long)_end; + else + symbol_end = (unsigned long)_etext; + } - if (symbolsize) *symbolsize = symbol_end - symbol_start; + } if (offset) *offset = addr - symbol_start; -- 2.25.1