From nobody Fri Dec 19 13:23:12 2025 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 273AE2D2388 for ; Mon, 8 Dec 2025 06:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765174995; cv=none; b=osYhc4l+QgjuKHOv+YCz2T6nC3fzq9MKqODO0wF2RzGEG7RMlL0ZnwY5ZjATLO2gWMyz7Z8hTPUgEgx5dP2v869UR45VxtS7Rx/lepQulVVafzJ4opNnGj7BnXa4c1r+nmbT5Bizb2bHHbuX1ufrQtIukZfhvOs4yfTIop1jroY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765174995; c=relaxed/simple; bh=5PZXQ0lfVCycMNP5oO+I4374U1dXCYUzUOah9Up10Sg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QNtlZj3p73BknMp6jPzWi5IgIAtFIvVOnwcqAx2KC9HiAiFYBy4SWJZyTAU0OCAzjPKq/G2wXfqsClH9RfrFuDsz/qpl9WlIUPG9pLA1CboPf21n83o9PWzhnglOqstt276pC2EcxRTcg6307DNqyi704XGzjykkFDBqn3qzgjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gWrx0LFy; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gWrx0LFy" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765174987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jd4R/6HSD4HfcnXGIikZ/cx0ryI1RWeea5PAWHJfTQI=; b=gWrx0LFyCYsrb8g64EoOTWyvPFhA+UX+y/qlDpy4OdLyY/1nOqqExQzaCJiZvSALsbd86u nQ25XIBP7WnOD19ytwRIIEg4o8O+R2dHP3Xx4SQulA3zbiJu59rfD/iiauPLaj15YzmU2H J0AfNhVB9UyFE7GsYWS+eB72knbRck4= From: chenxiaosong.chenxiaosong@linux.dev To: sfrench@samba.org, smfrench@gmail.com, linkinjeon@kernel.org, linkinjeon@samba.org Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, liuzhengyuan@kylinos.cn, huhai@kylinos.cn, liuyun01@kylinos.cn, ChenXiaoSong Subject: [PATCH 12/30] smb/client: use bsearch() to find target in ntstatus_to_dos_map array Date: Mon, 8 Dec 2025 14:20:42 +0800 Message-ID: <20251208062100.3268777-13-chenxiaosong.chenxiaosong@linux.dev> In-Reply-To: <20251208062100.3268777-1-chenxiaosong.chenxiaosong@linux.dev> References: <20251208062100.3268777-1-chenxiaosong.chenxiaosong@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: ChenXiaoSong The array currently has 525 elements. When searching for the last element, the original loop-based search method requires 525 comparisons, while binary search algorithm requires only 9 comparisons. Signed-off-by: ChenXiaoSong --- fs/smb/client/netmisc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c index 8a84f826d486..55100c2c14cf 100644 --- a/fs/smb/client/netmisc.c +++ b/fs/smb/client/netmisc.c @@ -803,6 +803,9 @@ static unsigned int ntstatus_to_dos_num =3D sizeof(ntst= atus_to_dos_map) / /* cmp_ntstatus_to_dos */ DEFINE_CMP_FUNC(ntstatus_to_dos, ntstatus); =20 +/* search_in_ntstatus_to_dos_map */ +DEFINE_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatu= s_to_dos_num); + /*************************************************************************= **** Print an error message from the status code *************************************************************************= ****/ @@ -826,19 +829,21 @@ cifs_print_status(__u32 status_code) static void ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode) { - int i; + struct ntstatus_to_dos *err_map; + if (ntstatus =3D=3D 0) { *eclass =3D 0; *ecode =3D 0; return; } - for (i =3D 0; ntstatus_to_dos_map[i].ntstatus; i++) { - if (ntstatus =3D=3D ntstatus_to_dos_map[i].ntstatus) { - *eclass =3D ntstatus_to_dos_map[i].dos_class; - *ecode =3D ntstatus_to_dos_map[i].dos_code; - return; - } + + err_map =3D search_in_ntstatus_to_dos_map(ntstatus); + if (err_map) { + *eclass =3D err_map->dos_class; + *ecode =3D err_map->dos_code; + return; } + *eclass =3D ERRHRD; *ecode =3D ERRgeneral; } --=20 2.43.0