Received: by 10.192.165.148 with SMTP id m20csp2433902imm; Thu, 26 Apr 2018 10:54:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49bMIRyZSHDSIUW5G0F9nWoUP9rJz4UAsDgnNAzZ3Ni6Ms0hHgl9XbxHASi2KAyKZSxrsPc X-Received: by 10.101.100.214 with SMTP id t22mr23437055pgv.41.1524765280614; Thu, 26 Apr 2018 10:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524765280; cv=none; d=google.com; s=arc-20160816; b=HalzE1Lw60R7qGaVRbrv0mjDeFIB1nEzCXzOQLHB4lv7BVLDobsiyPlkwRPScRqOFK FmkcdP8R3hP17VJzSDYsdIunU5OfKAgmDoCmx0eBMGWwxJNmjw59m+Vw9dpJdt2Kz9D4 XCOgQoJWdfjdnVl1nrtvv9SCLceU4jfAl8s03ny6CK+kVebt3mK4vaAdaq55tCOSA/II jHDzbiDEtzmKfUu1pHPPhtY5RDpX26noGSvgij+vMy8AFdhXkF+s8W2I4lKcK1FZ0e6G U3tklXm6OcTSTWAAeUVhjc3/CHlIIHknpMw3HBqJjVrswGitJhMqqCjtgI/Z69l68+JC tfUQ== 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=PTMGwsAiAg754UbZpS3d4sTzyEjFlhRxqzSmaW3GGiM=; b=Wf5lCuPZJge4c3os5RLYVWz0bPx/4kpusz5vFgr+nUHQ56RWEoWSjMkZbCow1LPYYs ONGVMSF+bRLNDZm+uUEPrbjgvuMwguXNO5YsWnwD53F7K1F0C1eL+xVY8iML0n/cUg78 d0NEB9TSME8UYY+WjcokQmy44WKHbjIYWgZW2BRNE8n/xo5W/IRwwVvgvCVQto8ezkMU 3mpdQoE7ijQ/hqlm98zekljcoIBKSwvg9gUqedsOOQIdFOkmwlPzMJ+WpkxsEunBCi2T 8esxduora0oFOE7h1gYUE9oPBZz4mkMn+WCKnTxeN9R2kHFyIFNCFqh8ZQymWREyP1vd uKyQ== 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.10.54.25; Thu, 26 Apr 2018 10:54:40 -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 S1756891AbeDZRxU (ORCPT + 99 others); Thu, 26 Apr 2018 13:53:20 -0400 Received: from mail.bootlin.com ([62.4.15.54]:60909 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754582AbeDZRxR (ORCPT ); Thu, 26 Apr 2018 13:53:17 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 669A420775; Thu, 26 Apr 2018 19:53:15 +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 shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [195.53.49.241]) by mail.bootlin.com (Postfix) with ESMTPSA id C82D72072F; Thu, 26 Apr 2018 19:53:04 +0200 (CEST) Date: Thu, 26 Apr 2018 19:53:03 +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: <20180426195303.1f08d2cd@bbrezillon> In-Reply-To: References: <1523276721-4982-1-git-send-email-geert+renesas@glider.be> <9bea3ad8-7e84-87c2-9963-de81ad4cb3bf@gmail.com> 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 Hi Geert, Sorry for the late reply. On Tue, 10 Apr 2018 15:26:20 +0200 Geert Uytterhoeven wrote: > Hi Marek, > > 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? Thanks, Boris