Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3718941pxv; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLMnd+oCPngvdyUGvCf2Ad18DRs8nElfdvOSgKVtYy3kF1uZgkSb8p0UdVz7F5LTYhxgkK X-Received: by 2002:a05:600c:4fcf:: with SMTP id o15mr37998wmq.116.1627319404166; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319404; cv=none; d=google.com; s=arc-20160816; b=cEAiwF+zE9teuUcFyNgf+TMBlhqaEMKilm0iBAQa2SGVaqNsI8Q/VZpjL8S9nvSFFg BjCRoRuIp+x7RWvujglIwuDm0x3YXD9XhkkF842T+Cjcgi6O197avDfenmZ9a1tQwuJ8 JAFWzswOJRMb5zgw9fkwwy000yPTtcD2GnHnVPmEUJuBzIg7NHutlIiN7knDzcugxuUc AmXQ8oeirJfaDzTy7P9yQgN+RbmhQ+Oy/jexBPGK333dwdBI0P3VP6JvNcLO9obL1Dca lp4Mqju6K50KoJH1uopkxWlrGGg4XhBgAAb04w5jd7ZLRMA47JBDBXX9uQIgTMfg2uta TMrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mBhsGvvW/2o72EquE75DiK3ee2ohso0EXQCoq+A1NnE=; b=u9fnM8yNCm63c0nBr+tU3PlQOobtYNE9AJTxzQ5ghit3wiefKsa7T3GlmzS2jZZOtR MwuvrR980XoeRpBAaZBnYt+4nD9N6GJxkKlpts9GYnR28tSRYTbHHTpN7S8g0U+sxuf5 nc2aQcJktEy/PPKuem1LYf+7dweR2c7LTMs22Kz+ygoPP1+iR7JKjk/Ku53tNwSF5ZGF +BsOwQPGAmJGuWrs2eoiRoRB5bXbqlCVhS9ciJ80vx0NuxOi1AuhS/b4Q8QTM3heWVBN sc5szGjKH4Ba/KVesdZBfEQRQHySXi2Zx8lzKWzHBQDqHz7CeR1yfQSc6HKXXTuPn4x7 ahLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SnPtGlLa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si177536wms.181.2021.07.26.10.09.35; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SnPtGlLa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238510AbhGZPnQ (ORCPT + 99 others); Mon, 26 Jul 2021 11:43:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:39348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237799AbhGZPYM (ORCPT ); Mon, 26 Jul 2021 11:24:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1BEA560240; Mon, 26 Jul 2021 16:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315480; bh=/sIjH0jkwG4GR2cVYMRa2esngUBVJDJRKHCiV0B+sF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SnPtGlLaa2r/OmU/5QFUDrwG5VDNJiLThFHlMSZlir49ZGVKbQ8ZRY46b9NSR1QDG xUjB72r/iaP0nWK17SzyxAjnSYtW+g6tlN7SqfDxNHInbv7h6sZ76Mt2a32c+tEf/f rlVJhlteq4riI68qe+xZfutjs9h6rtaTEqo/c3QA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthias Schiffer , Sujit Kautkar , Zubin Mithra , Stephen Boyd , Ulf Hansson Subject: [PATCH 5.10 106/167] mmc: core: Dont allocate IDA for OF aliases Date: Mon, 26 Jul 2021 17:38:59 +0200 Message-Id: <20210726153842.954553922@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephen Boyd commit 10252bae863d09b9648bed2e035572d207200ca1 upstream. There's a chance that the IDA allocated in mmc_alloc_host() is not freed for some time because it's freed as part of a class' release function (see mmc_host_classdev_release() where the IDA is freed). If another thread is holding a reference to the class, then only once all balancing device_put() calls (in turn calling kobject_put()) have been made will the IDA be released and usable again. Normally this isn't a problem because the kobject is released before anything else that may want to use the same number tries to again, but with CONFIG_DEBUG_KOBJECT_RELEASE=y and OF aliases it becomes pretty easy to try to allocate an alias from the IDA twice while the first time it was allocated is still pending a call to ida_simple_remove(). It's also possible to trigger it by using CONFIG_DEBUG_KOBJECT_RELEASE and probe defering a driver at boot that calls mmc_alloc_host() before trying to get resources that may defer likes clks or regulators. Instead of allocating from the IDA in this scenario, let's just skip it if we know this is an OF alias. The number is already "claimed" and devices that aren't using OF aliases won't try to use the claimed numbers anyway (see mmc_first_nonreserved_index()). This should avoid any issues with mmc_alloc_host() returning failures from the ida_simple_get() in the case that we're using an OF alias. Cc: Matthias Schiffer Cc: Sujit Kautkar Reported-by: Zubin Mithra Fixes: fa2d0aa96941 ("mmc: core: Allow setting slot index via device tree alias") Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20210623075002.1746924-3-swboyd@chromium.org Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/host.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -74,7 +74,8 @@ static void mmc_host_classdev_release(st { struct mmc_host *host = cls_dev_to_mmc_host(dev); wakeup_source_unregister(host->ws); - ida_simple_remove(&mmc_host_ida, host->index); + if (of_alias_get_id(host->parent->of_node, "mmc") < 0) + ida_simple_remove(&mmc_host_ida, host->index); kfree(host); } @@ -436,7 +437,7 @@ static int mmc_first_nonreserved_index(v */ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) { - int err; + int index; struct mmc_host *host; int alias_id, min_idx, max_idx; @@ -449,20 +450,19 @@ struct mmc_host *mmc_alloc_host(int extr alias_id = of_alias_get_id(dev->of_node, "mmc"); if (alias_id >= 0) { - min_idx = alias_id; - max_idx = alias_id + 1; + index = alias_id; } else { min_idx = mmc_first_nonreserved_index(); max_idx = 0; - } - err = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL); - if (err < 0) { - kfree(host); - return NULL; + index = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL); + if (index < 0) { + kfree(host); + return NULL; + } } - host->index = err; + host->index = index; dev_set_name(&host->class_dev, "mmc%d", host->index); host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev));