From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8068287263 for ; Wed, 24 Dec 2025 11:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766574446; cv=none; b=SYrX9hYqWvGe0N3ZP7V0NfAVkMUbKIkjra4RLJKZWoFh1TS556EHNQjqAaAfEQuzyzU4gczaCjtq1Vvf6sDLLzRLvPHmxrwN/rmr4GCaJpPny77gxTOEJ1w3VtAmq4RetkdgSburdP/uzd9sQaBhFEJ+E5ULC7fhzMHtrtOIvPo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766574446; c=relaxed/simple; bh=U0pJLDYpdoyfRuX5bQi2tjWSMSkAm6l36+A48xMAHWk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hsDzx4Jnpr9ObHOE+wBXvDt8z7OPJSRQZElCoFLcC/3KqzVkIgM9J//d252tcU+JYw6i/Zgb7a5iG4A39BFGiO9DjoavFXvdfODOd/jvcisOLkK1beDsemOOa9ElrnT/MWeqgov7B7F9/Xv3ThjbIqTK+qbfDVpVTNdeyID/hrQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pdvfZ7iG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pdvfZ7iG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37593C4CEFB; Wed, 24 Dec 2025 11:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766574446; bh=U0pJLDYpdoyfRuX5bQi2tjWSMSkAm6l36+A48xMAHWk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pdvfZ7iGYSicTsPNzDo1jo03WIoQkI1odWyCOyC6bweEPIHVjk7GSdhMtnfP06xxf noDIdvaZRqCanxes4oeLqVeeUwvPDYF24eG4QL1ZBGexos9YWw1Nzke0FJC8pqsXHQ zESGmLjGh4zmVatmDStRkLqB34zeb2m1sEfBvYHQ71bKJCktJXvjcnJuWt1Ic5uDfG TYCx7IPRAbAXc068IDoTAsFSZQL6qm+rDD41x4VSxIhcpq37YuFMBenrFppHDv/o40 4EKIa7jiiY+33fem7R02qkel+2vHO99IP+W8WbZ9GI6QJ4CsyBoS/ZJpVutHOZc6cZ 02vNqehW3mYvA== Message-ID: Date: Wed, 24 Dec 2025 12:07:22 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add() To: Haoxiang Li Cc: dan.carpenter@linaro.org, ioana.ciornei@nxp.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, suhui@nfschina.com References: <20251224105240.1588158-1-lihaoxiang@isrc.iscas.ac.cn> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20251224105240.1588158-1-lihaoxiang@isrc.iscas.ac.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 24/12/2025 à 11:52, Haoxiang Li a écrit : > On Wed, 24 Dec 2025 10:57:52 +0100, Christophe Leroy wrote: >> Ok, then this needs to be said in the commit message. > > I will add it in the patch v2. > >> By the way I'm a bit puzzled by the device_add() doc versus the >> put_device(), because it looks like device_add() already calls >> put_device() in its error path, see >> https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/base/core.c#L3716 > > I think this is because device_add() increment the reference in the > beginning, see > https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/base/core.c#L3580 > and if device_add() fails, another put_device() should be called to decrement > the reference which is obtained by device_initialize(). Ah yes, I see. But then all exit paths in fsl_mc_device_add() after device_initialize() should call put_device() ? Then in fact the fix should instead be the following, shouldn't it ? diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 25845c04e562..6d132144ce25 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -905,11 +905,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, return 0; error_cleanup_dev: - kfree(mc_dev->regions); - if (mc_bus) - kfree(mc_bus); - else - kfree(mc_dev); + put_device(&mc_dev->dev); return error; }