From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 C8BB2366822 for ; Thu, 21 May 2026 09:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779354459; cv=none; b=uR7av0FNwp/w7E5gGuwkg4JURwE5aXoOWMVtGdr/KEFN6okvSHMzUu5maaPRnPjkDZS8E/bqcCKsZTo1ARDWTPLYAmG/cFpCU+I+eQR4LKubNV38P54rOwxR6t+Ek83BG7LIdKfX4BekXo4OuILmgoItVXfgN73oCtwWgBw5RH0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779354459; c=relaxed/simple; bh=91QQINpqJQ4LAne0V/WZIX3VWZlJe2bHssd2YEiaLxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=quw4Zxgm69y2Yy+PoKcfMUmd42Hv5lLBngsHq27tBjHXpYneHFBMqKdx2YnSzljmNxjLTuM6KCjaEcymydXfV3Qma1Mcry60A0G/lxUSq9Djv0m6V/fj4wE55f0oj8TpJMyQwX3Rdm6LHkQtvR5A2WqZToYw2nzyDxghrROa3UE= 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=qGfzm4vu; arc=none smtp.client-ip=91.218.175.180 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="qGfzm4vu" 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=1779354454; 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=q6PIi1QDLQ8OiWtIk4Ayg6HwJRAUJXMtOoaQbIBan90=; b=qGfzm4vuEPBnDO187cwa572J3ejFLntC1T/y7X1WjBIPlOg3kHCqJdTijZrXfSErHvbwns 5Vf3ljA32GuaKOtDg7JLcOPDLwhdgg+C0a4YAmn5OfeMYO487+rkuh++OARMWcqPBM6zW/ hvOMHpTIA12WgP8Y9knM9oZomCfTa3o= From: Thorsten Blum To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Kees Cook , Andy Shevchenko , Yury Norov , David Laight Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Thorsten Blum Subject: [PATCH v2 2/2] string: use offset_in_page() in sized_strscpy() Date: Thu, 21 May 2026 11:06:58 +0200 Message-ID: <20260521090655.160282-6-thorsten.blum@linux.dev> In-Reply-To: <20260521090655.160282-4-thorsten.blum@linux.dev> References: <20260521090655.160282-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=960; i=thorsten.blum@linux.dev; h=from:subject; bh=91QQINpqJQ4LAne0V/WZIX3VWZlJe2bHssd2YEiaLxo=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFl8p81fnDSdb7vixZyanNulm5Xna/Z33i5Y61e++1dBR sO/lTy7O0pZGMS4GGTFFFkezPoxw7e0pnKTScROmDmsTCBDGLg4BWAiPd8YGf4uahT3FL1nzpNe wzrVcaPbB6/ZepKqMeePsR/nWnJqXw0jw7bW7/MiLqk+VfKXfjiB5bR/4gQnBc9ji7e5mxzadfT rLlYA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Replace the open-coded implementation with offset_in_page() to simplify sized_strscpy(). Signed-off-by: Thorsten Blum --- lib/string.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/string.c b/lib/string.c index 1f9297e9776a..7c72adc7377c 100644 --- a/lib/string.c +++ b/lib/string.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -127,7 +128,7 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count) * since we don't know if the next page is mapped. */ if ((long)src & (sizeof(long) - 1)) - max = min(PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)), max); + max = min(PAGE_SIZE - offset_in_page(src), max); #else /* If src or dest is unaligned, don't do word-at-a-time. */ if (((long) dest | (long) src) & (sizeof(long) - 1))