Received: by 10.192.165.148 with SMTP id m20csp2438124imm; Thu, 26 Apr 2018 10:59:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx49qRqFF/7RhmeP9NoNRADEFY8ZTRKgISohQ0nu4a/nOuf9lQ99LYRK/OZmz7zgOKPJ7OJx1 X-Received: by 10.98.30.4 with SMTP id e4mr33619900pfe.212.1524765574451; Thu, 26 Apr 2018 10:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524765574; cv=none; d=google.com; s=arc-20160816; b=SJHtGS4a6fSO9lSZSo5ZpKjjtG9qHy/aRlgv7GL4oZtfxh2DdkoL76cFNH99pqqsnX c32/dEyqkOmtORTHw+eruR2oeqQ2yq+FrdHBZYcQTVajHo008F4r6bD8HPCx2KJhdr7B awipbQqfrLvCpWFhVuN6jNP8+n2w9Y1j+77W/O8DVEkuAO2kLwgxFDTtEFQsyexxwUx4 PtoJcDv+h+5y5ak/kIYyw3KuAbOA2RSW671UfhdU1lPFpJYTAU4/l7ILBMTyDrkBv6sx Rceo3aVvYAJF4Ty+Ohb5of58Pd9Bt09GH1TtZgbB8WQz09uvBf/Eoz7ceGSUEhcL7pnF 7Pzg== 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=wiGsB0hrcLirstKjbcW2lLTti+fGJp6Q4pK+zfDbF6A=; b=NMzq0in8YwUNGsBYJfQbIEmbpURDVzAJy9INyWglEavlJqLeo8kKhqSppE7fys8DzC Q1+nM+xinf90IsCPNfNthd9yskGVqlDRTAVKh1Vm/pwPyDEB8Mhi/A49xGfDV5YPJwzw zUVagrNH/j4fwjyd/ZQhfm2ws+f9bRscUPqnhJqY3Tiz8rRLFSL2Lf2xU1spYvUxNn4N nU8nEC4zISXCf4FXyNaaiy6/dsY9IEhti32lPu+AlACACeXhD6DXc+JbwvmvH8m6g2GI 8CkEkMupMDe7HsXuOnUhGXYigeDFM5h0PCVLx7tDGSiuZ7hbwLeDBgZvSGe/vAj3I5iz J0Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=q5wKYNOk; 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 l27si13233342pgu.353.2018.04.26.10.59.20; Thu, 26 Apr 2018 10:59:34 -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=fail header.i=@gmail.com header.s=20161025 header.b=q5wKYNOk; 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 S1756863AbeDZR5D (ORCPT + 99 others); Thu, 26 Apr 2018 13:57:03 -0400 Received: from mail-vk0-f54.google.com ([209.85.213.54]:46918 "EHLO mail-vk0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754014AbeDZR5A (ORCPT ); Thu, 26 Apr 2018 13:57:00 -0400 Received: by mail-vk0-f54.google.com with SMTP id i190so3538391vkd.13; Thu, 26 Apr 2018 10:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=wiGsB0hrcLirstKjbcW2lLTti+fGJp6Q4pK+zfDbF6A=; b=q5wKYNOkwsjhXpA6+O/8k3a+Ijvn3FvzifmGSQLtE0WXg66Qsq69f/4ve8SM+aetUe 2ZFsDUIWTQs1/nKbxnw2LVc1LWypN513xfHVRC4OIRZWEhPpHew/o6uHUvNFgBowKTPl qQTfLxLUl86yH6ildTOMU1jqFHUQ8wLx8zQlETvmTPMJhTvJJhtjfLbINHyw+GW2hlea Q4mUyepAXOcB9fnfH9kg+3RZIjfN85ZNRq6+Aqbwyq21IbijyA4aNBUAfeIqAzDsZK2D QGlQ9vScVczS/1Cr/926LPey/1jHQ3EHwgLH/nqL6kntQiYcK4g8WE+kBUf3ItxXoIGb RaNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=wiGsB0hrcLirstKjbcW2lLTti+fGJp6Q4pK+zfDbF6A=; b=frkFFtCqpIMXbMhoFaeiikFcuVbsY8EpMKFX2FmGTui8GEzi2K9TL9eJd38qi62Lfe qWxKQXDCmGO4I3MJ1sq75uMPdDLJ/Psq5wzWuTanddxjNubZEi4/8eFB3vGRxsCp7zc4 qfgG1cbRbrhTuThDAqQYsyKGG2dKQ8BuLgNJsK+j0BY/fjzxGZQWiOLYl7pqtlQQ3Cip j6QUotvBTy5Bp3AWfSs2oJ6MG1bbJ3FhYSprFCsXN5DIsllSjaKz79ruOblL2K4v97yt TW4T+DdipLtaYTyQUH8oPweWEUYvf/ceuQ0ZO26CszuvafiVA73udslNiRDH/vLceUOz DMaA== X-Gm-Message-State: ALQs6tDYmSOBTG/xq+Hyd/sTMPsY8XgYQfaiEv9y0WH2lZyq5Akk15nX D6uW82LB7FD/42kX5DKC8vRr2fqUZp1imW2PS1wU6Q== X-Received: by 10.31.137.148 with SMTP id l142mr24108847vkd.50.1524765419199; Thu, 26 Apr 2018 10:56:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.122.68 with HTTP; Thu, 26 Apr 2018 10:56:58 -0700 (PDT) In-Reply-To: <20180426195303.1f08d2cd@bbrezillon> References: <1523276721-4982-1-git-send-email-geert+renesas@glider.be> <9bea3ad8-7e84-87c2-9963-de81ad4cb3bf@gmail.com> <20180426195303.1f08d2cd@bbrezillon> From: Geert Uytterhoeven Date: Thu, 26 Apr 2018 19:56:58 +0200 X-Google-Sender-Auth: evvzOJKHIUZKXpf2Ow15vhDGkdg Message-ID: Subject: Re: [PATCH] mtd: partitions: Handle add_mtd_device() failures gracefully To: Boris Brezillon 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 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? Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds