From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 9FB8F12D1F1 for ; Sat, 18 Jul 2026 04:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784348532; cv=none; b=hQpoHyVwGPTGR8n0MQY/B5bJ5RrFtrSojkuMVUWtBC67qHzqbf+pIDuogA9pymEqFuzONIooBw8HL4Lf3QqQu/e5ZOq44H7QDwAtWKg722N5jPsM6mCAsvYZ1ZIteQ1zKn5Nyxq6U+6/OgA0nsFNTGPddCM1KrMPWqANK6VltZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784348532; c=relaxed/simple; bh=0L98YV3teSYwb6lfmt+EpCQhg1PcsQ5fDtsTmkzgYqk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WP16+EWAymr4BEIFDuwsx/T6AUVAGmA9IvHB4nupW3uWU9fOqWYrcOrls50IUqA4wJlXhmhWa4e/xtzwbKgO5glOOQ0catMt3OAwi2PBjUTpbKyrHpIyfNx0++xo6vxdWu/fL1SnLXO5L90oPwPS9EuUBgWrsvigcRoYoA+6xU8= 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=fKPYm9uc; arc=none smtp.client-ip=95.215.58.186 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="fKPYm9uc" 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=1784348527; 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; bh=1fOEke3Ii5daBW+W7PdOzih3poWiSGjJ4vZ0BCYzOUs=; b=fKPYm9ucFzeWj8efizn+ldkmLjxHpuE18lguhWUZoaAAGhz4TzPfBOEoE8Qu0ywjzQdR+Q WhhN5aERroAFwpfnTGJG6V/O3C04HLpQf10nuLiBpGM6LR5v0EP6XRk1ZypW9thnLYEmyV VUF4gg1r934wy0cRUJAJaJOlDbMI9io= From: Jackie Liu To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] lib: cpu_rmap: reject zero-sized maps Date: Sat, 18 Jul 2026 12:21:55 +0800 Message-ID: <20260718042155.31020-1-liu.yun@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: 8bit X-Migadu-Flow: FLOW_OUT From: Jackie Liu alloc_cpu_rmap() assigns an object index to each possible CPU using cpu % size. Passing zero therefore triggers a divide error instead of reporting that the map cannot be allocated. Reject zero along with sizes that do not fit in the u16 map indices. Fixes: c39649c331c7 ("lib: cpu_rmap: CPU affinity reverse-mapping") Signed-off-by: Jackie Liu --- lib/cpu_rmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c index c86ab6e55d17..bbb41d37acb1 100644 --- a/lib/cpu_rmap.c +++ b/lib/cpu_rmap.c @@ -28,8 +28,8 @@ struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags) unsigned int cpu; size_t obj_offset; - /* This is a silly number of objects, and we use u16 indices. */ - if (size > 0xffff) + /* Empty maps are invalid, and we use u16 indices. */ + if (!size || size > 0xffff) return NULL; /* Offset of object pointer array from base structure */ -- 2.54.0