Received: by 10.213.65.68 with SMTP id h4csp4128596imn; Tue, 10 Apr 2018 09:38:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/oVt4vdrumfln6SnQdH/Jbwx/+w7BgidlIZOGJIMYwzmxiGUXXXxnVilCUeY7tdRnirmz X-Received: by 2002:a17:902:122:: with SMTP id 31-v6mr1218728plb.280.1523378330563; Tue, 10 Apr 2018 09:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523378330; cv=none; d=google.com; s=arc-20160816; b=TtRVjD4MsnyFEeZ5OmDVVpCSUzw02IjkDojoPv0FafZsvw3DN+3hqNGrMoWB+RCpms 5KObfA1LSLp7cWPiOWCVjABU6kFWJInSuqt0GvtRm2xreyYBDMjze7GVWidr/yjJ8/zC LWREatc1u8MCF8TFZ6HhZMRdk1YGyZ3co/6+Y1UqKwD2BLMztKSno2J4sm++ByNGCnss TEJ7N3yVcswr9pDbde8pa/cxhD8vvP025C/qU2M8Vyzci8V/PWVSq68zQ/7ETHJhjkBx ouAOS3AqWRfU15uI0jmwDvq9LNHk9sxfXQcPHiqsJi3hW0uDsjQS9IpEsSA3G6lQSh3w zqUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=D4crQTX8H/f7MjclAHMzKxgycBsnd3I2LrUWpUt2YTs=; b=mo04VKNh1LDBL9yb5mCsLzMdgpOm6U9DgjwvfDcAzZ9lvibGy9Z/nwmhLLH5/dHz2D hIJU/xOVTsJ9kAPeljVHvujTiGQNrLSXslJ4d2G+czjreBOrCZnFzJq55zMeo5ryx+g9 Zosb0Odq+RRvN0pm85iZuEql0Eo7P/j61d4rNTN3LGoHsR+h/Tc1rtiD6yuo1z8udzXZ j5OTxvbyfMASOvVTv2EAPkZMl9IlFCZoXjkLpQx0rAIYuo34Liz40+ave8/5UY2KroLR 1s8PFits+5qSZgzUsqKbFiOBnEB0f2FW3LZXC4XPOUSnprz+CWCMsfkYmbd1TCgtSH7U GpGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TCx4mnz9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21si2372398pfa.377.2018.04.10.09.38.13; Tue, 10 Apr 2018 09:38:50 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TCx4mnz9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbeDJQei (ORCPT + 99 others); Tue, 10 Apr 2018 12:34:38 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:38880 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751774AbeDJQeg (ORCPT ); Tue, 10 Apr 2018 12:34:36 -0400 Received: by mail-lf0-f66.google.com with SMTP id u3-v6so12595025lff.5; Tue, 10 Apr 2018 09:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=D4crQTX8H/f7MjclAHMzKxgycBsnd3I2LrUWpUt2YTs=; b=TCx4mnz99tDT3G5oRw7Bx4JU4E8Fs1VsfZvwF13ebdRUnELqJ+vCum6Rd4XADIb7Op WVre9ZXMiWP9QI4aHaJm8y+Gu5x2RpjOCnUjJWmJYaEDTg9dA+wRh/Kc/020ETM3BTNt 3rj39racUpr0XxP085kTjtB5FD4HTY39kV3eMBQXtxtdu5meMV7HwLCF9HctDakMHVMr M8EcnxTJ03wT4JvXMtrS6eumbnWll1Y0XQ3aPyX6ni1zfBdwuAHuaYDTSgluPkrHhEJG AeRedv6Wv9srDR45zxhtVut+KPXC+YA/WV+NvSjGzoAUMbJupZeTscmwELY6UH36WsTy srDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=D4crQTX8H/f7MjclAHMzKxgycBsnd3I2LrUWpUt2YTs=; b=BVr2HX8+l4AQpEXhtvdlLlruaf4dKydOdwj4BCxEzp6nat5O77d44680AmeMVGQyL4 NhVTkwUe0okK7czEGL0xs63sAY/6eiFLhMBtMQYiHjT49vBiLUzQVj2jUmuxvNLDc9Ax hEMzPJtk08J9NnasLyOdaLDEz5yksDPgjeEa2103NZkU+sKgQNuL+CjKI4dEmIwlFebW K8a+LlHX/cCf98NCvWzHzfLk/kPGwJ3gMCembKbCmiXGOBfzh3vY9FbIzJKb8sufrQ6h PV/ouCYTIaz64sYJ1PkMZtv357DsnSR5imsT8Tu1+IRSg6GY+OQqaNsEgBzw69lBqT3k 18sg== X-Gm-Message-State: ALQs6tDoSVWl35I/E08NPjAew4Yvw8bUPNsUDSJuu9FIiuH/Q+vfJCLG UmvevSG/HDM/4P1nPCJ73viwsLPeIuPJIGh2HKhiCLAh7yI= X-Received: by 2002:a19:cfc2:: with SMTP id f185-v6mr683837lfg.75.1523378075103; Tue, 10 Apr 2018 09:34:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.114.20 with HTTP; Tue, 10 Apr 2018 09:34:34 -0700 (PDT) In-Reply-To: References: <1523276721-4982-1-git-send-email-geert+renesas@glider.be> <9bea3ad8-7e84-87c2-9963-de81ad4cb3bf@gmail.com> <87feac02-e955-1897-d4a4-d6d6d1082e45@gmail.com> From: Steve deRosier Date: Tue, 10 Apr 2018 09:34:34 -0700 Message-ID: Subject: Re: [PATCH] mtd: partitions: Handle add_mtd_device() failures gracefully 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 10, 2018 at 7:47 AM, Geert Uytterhoeven wrote: > Hi Marek, > > On Tue, Apr 10, 2018 at 4:37 PM, Marek Vasut wrote: >> On 04/10/2018 03:26 PM, 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?". >>> Note that if we go that route, it should be a "soft" failure, as we >>> probably don't >>> want to drop all other partitions on the device. >> Is the number of partitions ie. in /proc/mtdparts an ABI ? > > I don't know. > I don't know if it's an ABI, but having consistent /dev/mtdX numbering is important, even in the case of a failed partition. Many scripts on embedded systems are hard-coded to /dev/mtdX identifies with the expectation that they can access a particular address region of flash. I'm sure that's what the "let's register it anyway to preserve ordering" comment was trying to get across. I've even seen weird things in dts files where later entries specify earlier addresses in order to leave the old /dev/mtdX numbering alone. Obviously, a better user solution is to construct the mtdX number from /proc/mtd based on filtering for the name field, but not everyone does. I'd be wary about doing any fix that disturbs the numbering as you'll be disturbing users. At a minum, a loud warning in the log. That said - obviously fixing the kernel crash must happen. - Steve