Received: by 10.192.165.148 with SMTP id m20csp2450346imm; Thu, 26 Apr 2018 11:10:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx49GGkn/t4nTeamxv9V7ku5dT9ZZY/RXghGBDuXAX5/CgWLZ9Gn8vBPE0kxKB/3n3eSPjZ3A X-Received: by 10.98.68.86 with SMTP id r83mr33479459pfa.145.1524766258625; Thu, 26 Apr 2018 11:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524766258; cv=none; d=google.com; s=arc-20160816; b=uvexyk6kx/9pOwiuQSmYOtt6ZDag8Y8pzcxwpvYGW43IThfsCr/R2Q2nwGbDTGO7IT ZdiNM82q2TEeedDwbQ0iCjstUHnq4P04a0WXFqYV7tRGdOilobd8jEGioOb1cXVyFyyi eT5+B8ELf18/JACsH2pv6xnm9tQtdk7en3/e0jo5yoENECO6gBlEplURq1U/X1G3vQlt J/z/4bLfqWF4wGDx7em854qP7p3meZWRv/I15sQvC6cCzLKZeHyFGM5upcsvlJllsZep r5db5LwoyZI4Z9MRXBK6+vtB8Ib9tKVXwI8VcPqVB1Ns65GO4+is3MgaVDX+CV/hfzXb P/hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Wok4kY0gvkJCDgd3P2tHDyA+j1VALG1MXMGXn3lcaGk=; b=h0VjaBQaFVGs0wUoVSLQKEi5agHvxXyc8yxasTslhBwZrvKaZOVbTF4YzJMaeVYIIF b/4odpMIGCfro0zTJf8OBoRLMvI37iYrk69XzjxU1W4u5XOfDoEViywiK0d/hiJXHViH NLsO4mcs0gFKmfzD6dU1n6f3Y1OBrydTe+XOYupEqO/z6sHX//REJ4ah/EgVpb/GYKNo Boyv40Qq/aoAeZrpKzXgF2qHVq25YGsQD4TTGSyKeL8KIK/GubN46pZ9DAaXixtf6ItZ xucnsrYvW3K7md+PkGl0cxuh/BJe4Mq9RGwFS/p0O4sh0CQ4TXq2rkG663I8C75ysqWT GDLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l85si18897081pfb.231.2018.04.26.11.10.44; Thu, 26 Apr 2018 11:10:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756891AbeDZSJk (ORCPT + 99 others); Thu, 26 Apr 2018 14:09:40 -0400 Received: from mail.bootlin.com ([62.4.15.54]:33147 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754014AbeDZSJg (ORCPT ); Thu, 26 Apr 2018 14:09:36 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B54CB2072F; Thu, 26 Apr 2018 20:09:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [195.53.49.241]) by mail.bootlin.com (Postfix) with ESMTPSA id 2F4D9203B7; Thu, 26 Apr 2018 20:09:24 +0200 (CEST) Date: Thu, 26 Apr 2018 20:09:23 +0200 From: Boris Brezillon To: Geert Uytterhoeven Cc: Marek Vasut , Boris Brezillon , Geert Uytterhoeven , Richard Weinberger , Linux Kernel Mailing List , Linux-Renesas , MTD Maling List , Brian Norris , David Woodhouse Subject: Re: [PATCH] mtd: partitions: Handle add_mtd_device() failures gracefully Message-ID: <20180426200923.4a13474e@bbrezillon> In-Reply-To: References: <1523276721-4982-1-git-send-email-geert+renesas@glider.be> <9bea3ad8-7e84-87c2-9963-de81ad4cb3bf@gmail.com> <20180426195303.1f08d2cd@bbrezillon> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Apr 2018 19:56:58 +0200 Geert Uytterhoeven wrote: > Hi Boris, > > On Thu, Apr 26, 2018 at 7:53 PM, Boris Brezillon > wrote: > > On Tue, 10 Apr 2018 15:26:20 +0200 > > Geert Uytterhoeven wrote: > >> On Mon, Apr 9, 2018 at 11:59 PM, Marek Vasut wrote: > >> > On 04/09/2018 02:25 PM, Geert Uytterhoeven wrote: > >> >> Currently add_mtd_device() failures are plainly ignored, which may lead > >> >> to kernel crashes later. > >> > >> >> Fix this by ignoring and freeing partitions that failed to add in > >> >> add_mtd_partitions(). The same issue is present in mtd_add_partition(), > >> >> so fix that as well. > >> >> > >> >> Signed-off-by: Geert Uytterhoeven > >> >> --- > >> >> I don't know if it is worthwhile factoring out the common handling. > >> >> > >> >> Should allocate_partition() fail instead? There's a comment saying > >> >> "let's register it anyway to preserve ordering". > >> > >> >> --- a/drivers/mtd/mtdpart.c > >> >> +++ b/drivers/mtd/mtdpart.c > >> > >> >> @@ -746,7 +753,15 @@ int add_mtd_partitions(struct mtd_info *master, > >> >> list_add(&slave->list, &mtd_partitions); > >> >> mutex_unlock(&mtd_partitions_mutex); > >> >> > >> >> - add_mtd_device(&slave->mtd); > >> >> + ret = add_mtd_device(&slave->mtd); > >> >> + if (ret) { > >> >> + mutex_lock(&mtd_partitions_mutex); > >> >> + list_del(&slave->list); > >> >> + mutex_unlock(&mtd_partitions_mutex); > >> >> + free_partition(slave); > >> >> + continue; > >> >> + } > >> > > >> > Why is the partition even in the list in the first place ? Can we avoid > >> > adding it rather than adding and removing it ? > >> > >> Hence my question "Should allocate_partition() fail instead?". > > > > I'd prefer this option too. Can you prepare a new version doing that? > > OK, then I have another question ;-) > > Should this be a special failure, so all other valid partitions on the > same FLASH > are still added, or should it be fatal, so no partitions are added at all? I guess we can go for the "drop the invalid partitions and print a warning" approach. Anyway, I'm sure people will notice really quickly when one of their partition is missing, so it's not a big deal IMO.