From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7973C3EDE76 for ; Wed, 22 Jul 2026 04:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784693980; cv=none; b=sukUG32X/u1spO5zOaoR2iGiHEdLM0yZt/r1+8bOOiN5QdXdNGbqCyLvNdHbxoQO68zYoW+xVPoTGH1mZsBwGRhuSeYCvB8lLKb1YHXkUBy6iRdFI8QMQOqllAAdIm8hu6OJSQRoTkj7VngOllD5gl5v6DeOojpjlFL2fYNelWc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784693980; c=relaxed/simple; bh=5TBkJUmKdhQevSa2eaJlaerYZHy+ssjJms/0e9NQnkc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AYxpZkzOHp1v/NWTNl9Yw6sY2YBDZHEl9YoRK8d2jmxDKLmfXDTV4rKW4cHU6ceSl3mtFJM3QGB1O2kELEw3spWlMv3USiPDcwVGHvuWatljifnhS1MLAsIvJlxQn/oOyvrWWCLhsM/iAw4M6IKsAUb4dmHzShpT+95iPORgCO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from localhost.localdomain (unknown [111.196.245.140]) by APP-05 (Coremail) with SMTP id zQCowABn1T_NRGBqYj27AA--.34365S2; Wed, 22 Jul 2026 12:19:25 +0800 (CST) From: Pengpeng Hou To: Miquel Raynal Cc: Richard Weinberger , Vignesh Raghavendra , Amit Kumar Mahapatra , Luca Ceresoli , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Pengpeng Hou Subject: [RFC] mtd: virt-concat: define duplicate partition handling Date: Wed, 22 Jul 2026 12:19:25 +0800 Message-ID: <20260722041925.31407-1-pengpeng@iscas.ac.cn> X-Mailer: git-send-email 2.50.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 X-CM-TRANSID:zQCowABn1T_NRGBqYj27AA--.34365S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJrykuryrKF47JF1DJF4ruFg_yoW8tF1fpF WFgw45Gr4DGFWFkw4DX3WxAa1fta97JFWUJF15Xrn5AwsxXF92kFy2y3Wj9a1kWr1kCr42 vF4jgF1kCF43AaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvY14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26F 4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AK xVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFyl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_ Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UTnQUUUUUU= X-CM-SenderInfo: pshqw1xhqjqxpvfd2hldfou0/ mtd_device_parse_register() contains compatibility handling for drivers that call it more than once, while its comment notes that partition parsing can register the same partitions again. When CONFIG_MTD_PARTITIONED_MASTER is disabled and the first call finds partitions, the master itself is not registered before parsing. A later call can therefore reach partition parsing again. With CONFIG_MTD_VIRT_CONCAT, each newly allocated partition whose OF node belongs to a virtual concatenation reaches mtd_virt_concat_add(). That function appends the partition based only on the OF node and increments num_subdev without checking whether the node was already added or whether the fixed subdev[] array is full. A repeated parse can therefore append the same node again. If all configured slots were already populated, the append is out of bounds. If other members are still missing, the duplicate can make num_subdev reach the configured count with the wrong membership. A local bounds check does not seem sufficient for a correct patch: - concat_node_list and the concat population state are global, but node creation, addition, join creation and destruction have no common serialization. - mtd_virt_concat_add() returns bool. false means both "not a concat member" and "not added". Returning false for a duplicate makes add_mtd_partitions() register it as an ordinary partition, while returning true without storing it would leak the newly allocated partition. - join creation and destruction call back into MTD registration helpers, so a driver-global mutex must have a carefully defined scope to avoid recursive locking. My current view is that the fix needs both a serialization contract for the global virtual-concat state and a tri-state add result, so the caller can distinguish "not a member" from a duplicate or capacity error and free the new partition on error. Would you prefer this serialization to live inside mtd_virt_concat, or should the MTD registration layer serialize the node-create/partition-add/join transaction? I have not attached a patch because choosing either scope without agreement would encode a new lifetime and error-handling contract.