From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 020A4146A66 for ; Fri, 26 Dec 2025 09:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766741724; cv=none; b=uFrShNlpILeqKiB9cL0HZOEtH+g+/bLPhyGeywVCYBIOsh5HhpiWMvF7Oc9eyCwly98yAAOzWpc6KAAG2Arr7uOtKL2AW5o+aOKghrcW0j9fBUSjdmZs7luOwza1NaTNew5AFMSULOVCzKNWwrJwfVpAHkbk8Jw6wlbUhEysdUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766741724; c=relaxed/simple; bh=6hIOGHPOKIRJvT/7CZBPFrFbLkBHUHW+2ofARDxki5E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=anjtPa2qC4NsXVBQyDFqSjN5n+RiBdC+6n2MN57DJj2qsjb3/8GEDsXCQfZQnU+nxjkSEwitRth0KtYCGujXJcLn3Z+kBVl3C2KnBotxfjffvZMNSpPcKqaCS1hn06EU2sgzihArvsiAn12aXGfRISaoPrmA1BAl6YoE9JDGlno= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=hJXmz4TH; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hJXmz4TH" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-477619f8ae5so41719465e9.3 for ; Fri, 26 Dec 2025 01:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1766741720; x=1767346520; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=rpUYSN7LOfndvWeXD71hxMCopt3fFad/Uy55qlltHmQ=; b=hJXmz4THZLwNeIBv15nHMk8qtRQrPlgFuGpf8K0Hqj04jMkkDNhvzrP+Z1n1Vg5b3z ewbjSDZ4OugAIon40HV5bnTNjM2CSv8D4XCNdAUaHo4I1127sJvzDRZxZcQsy5q0BO7V o2/3l7HKBh8SRGsl0QH70GxGaf7RxdJu8PHnPa2wcRJeqKoLoT1XjNr0Vs5vSmzoGXfL 0a0Q//C5/gYg/7qqSAa5KhGW7oh9MZbsDuEjO77oP0TO5Yt8gleQtBz0Eg5AaoDL5zSV QzGk9RPYL6xhj20GcrzK9c6TCR2AvqUjBpkQaCYpeZjG5m+2SKYNTt1DcsBFn9vnVw5D DjgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766741720; x=1767346520; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rpUYSN7LOfndvWeXD71hxMCopt3fFad/Uy55qlltHmQ=; b=SxpjenC1VeJmqovcqFcn2ZuD609vCh2g2CBE8g/Rvxp1ruPw+Tzwc136hkcaAH8evn Xk2ReurrIRQYLOk9zzAxY9gk+N8ARFNdPaGdjgsQbCC5FZcqif4n+nC7xHqhSxQ5i81T JtiYawC73JeKQHTihHleP43E/8j//DWH7uSVswLnMd5RZLDXuv3gQySaiCAeKc+dxoHx uI+44ZgObalRyJPa+EuemeAy/82JlJ2nKUBv3DDWPuYVdXNumgi8G3gxItZpGOq8f4fe ZtFcTlowTBvWP02GxuDCFeWK6PMA4isQRojrBCkRHRlRbK5y4Z9S95IwZrNFPHvFF6/5 cIrA== X-Forwarded-Encrypted: i=1; AJvYcCWB97mR37vd/xbeEZpQwfRe69CV0Q+jogxEq2fx0Ut9GSP8Cmg+xrYz9uNYHoDsyIXdKJXTsH/YWowIS1M=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1o/dzkxRjByFmlA7uCrnkDzWKReAzG0JwALjWOMfX2hgVuCAX vDjFF/hR6/3q5i4bie9PbJ25NUiTh8w/5YbJMn4R7XZJCqyLvyx7NQuhqTQZZCEx8bc= X-Gm-Gg: AY/fxX6UCFITCAZPkGBMKSJixWjNYOcaQDeQ5A6donhx4/jzBWPSBwdn4swzleWr5uF UiKK0jLX+Np36zdFt1SEeBbK4K4eMcFJk7DmyBwYWoHFMILhr92ZnhpIGJyaaDw4uy+POiJkuFz APT/OvSrsqHgX4REffTS+xgDYiCjcXplzxRHdEggrgvx762WbjtXTJ2caiHRYbyk9HCPK/62p3N hMpV40zapqSNg6Fp3sPLTVpyTC78665McwzeJGQiKVYW7bwNPvyRMHJ8xwGkptNu9X3wJz9549n b6Xkbn/af3TtVcyn+5Xo1RA6yjDgRDyO7hNmcpFHezzV/P7B4G4mq9uThvsD3+4VzSjKESfRQYL QODiDAorH2G02LEQ67aywwjfZdtxer9LNhzKZgUI1Z7Eg7RTD2BE/Y4e5g/bciFlQdfBzi1N0y+ pvIOTTcasRWuahTRGE X-Google-Smtp-Source: AGHT+IETp9OnXTxIUo3XNBLgddP7lEA3N3rRTgRdN8yeWCcT0DcWuRaZ5faTgsy/Xb0aILvmgm3E5A== X-Received: by 2002:a05:600c:848c:b0:47b:d949:9b87 with SMTP id 5b1f17b1804b1-47d1954a485mr210168905e9.12.1766741720119; Fri, 26 Dec 2025 01:35:20 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be26a81b6sm447635155e9.0.2025.12.26.01.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Dec 2025 01:35:19 -0800 (PST) Date: Fri, 26 Dec 2025 12:35:16 +0300 From: Dan Carpenter To: "Christophe Leroy (CS GROUP)" Cc: Haoxiang Li , ioana.ciornei@nxp.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Su Hui Subject: Re: [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add() Message-ID: References: <20251222074958.992911-1-lihaoxiang@isrc.iscas.ac.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Dec 24, 2025 at 10:57:52AM +0100, Christophe Leroy (CS GROUP) wrote: > > > Le 24/12/2025 à 08:54, Dan Carpenter a écrit : > > On Tue, Dec 23, 2025 at 04:34:44PM +0100, Christophe Leroy (CS GROUP) wrote: > > > > > > > > > Le 22/12/2025 à 08:49, Haoxiang Li a écrit : > > > > If device_add() fails, call put_device() to drop the device > > > > reference and do the cleanp. > > > > > > > > Reported-by: Dan Carpenter > > > > Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2Fb767348e-d89c-416e-acea-1ebbff3bea20%40stanley.mountain%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cfd3865935a164c2083cc08de42c1b5a5%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639021596902232212%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=j5%2BqptzXvrxcnaaH3PIDorAYMexoPmf3PWi5GbpVD9s%3D&reserved=0 > > > > Signed-off-by: Su Hui > > > > Signed-off-by: Haoxiang Li > > > > --- > > > > drivers/bus/fsl-mc/fsl-mc-bus.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c > > > > index 25845c04e562..90a2107a9905 100644 > > > > --- a/drivers/bus/fsl-mc/fsl-mc-bus.c > > > > +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c > > > > @@ -896,7 +896,8 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, > > > > dev_err(parent_dev, > > > > "device_add() failed for device %s: %d\n", > > > > dev_name(&mc_dev->dev), error); > > > > - goto error_cleanup_dev; > > > > + put_device(&mc_dev->dev) > > > > > > This change has obviously not been tested, not even built. > > > > > > > Yeah, it doesn't build. > > > > > And by droping the goto, the kfree() are not done anymore, leaking > > > mc_bus/mc_dev p kzalloced areas. > > > > > > > Calling put_device() triggers fsl_mc_device_release() which does the > > free. > > Ok, then this needs to be said in the commit message. > > 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 > It's refcounted. It calls dev = get_device(dev) at the start so it gives up its own reference at the end. We need another put_device() to free everything. regards, dan carpetner