From nobody Mon Sep 28 23:55:27 2026 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (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 D0A673E3178 for ; Fri, 14 Aug 2026 21:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; cv=none; b=sikKIdn5w2MkAhJsngXRUyS4/TjRhh6hg8qP5UQBZ9ghbp9JhQSlc8XR79yXFFX7L3kbPOMT2w/+c0LN5piRdfajh2xGo1AtFfHYfdDwPaX46Vrevw4E6M/w5Qb/ZlztJSF9+0xKJKe1MIt2lgQGjIy4fDr/2/SK2I7Dcqu/L5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; c=relaxed/simple; bh=V/hULih2EckfZRoUvl+6d5z3CCjHaGcqYA0HdEmXY2E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QL6l4oql1QsULcPOcU63qnHaSqZbiDJfhClBdTMuydMbZr15w0UabIqFVcMGBUymY9+9BGq8DAPhQYZW+WCdzbrrM1lPyhF5N3bZ0aOCv1HcNsVPgdj1W3PRkkwN2FG7sILzRWxqRHiVMSYEIWVX6K5oouR53UZrQ4OmfUxtEBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X73Qiui4; arc=none smtp.client-ip=209.85.218.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X73Qiui4" Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-c1f472eaafbso230900666b.1 for ; Fri, 14 Aug 2026 14:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786741261; x=1787346061; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DYuMpnr3KSC7nQvSYxrDe2V0WmDtuzggqBjS2om2eUA=; b=X73Qiui4ACrKxOTzhrvIsSD4XSn6hQjsjU5sDjUBDUiDF75YTNQdAytZAGrfr1z+nr sbIhFVV2QRXMeXTMqA+F31S6iQB13pUSVBeDRXb2onh6i8542tgGmWCc/DCnG6EQC3bg F9Fv0AZuJUo8Do4M8L0N5svDbwCp2N6GyQ3dWbzogf4TGJokrZGLY9DEBacBrTHWfMsj VLrfDW+9uCI9N8NXpGT+ITAOYlTpsZIHNN7AHhreYba2nqy5pGnOYYPALZDkl0HtCcxX GySKOlQF3+yUtuN96tGkhrdVT6dNaAijnVCkVheYkicF6MiJZGU/DP97cFbJZrncPw2r 5tHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786741261; x=1787346061; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DYuMpnr3KSC7nQvSYxrDe2V0WmDtuzggqBjS2om2eUA=; b=eZj3vvFpUrptYbz8b3B/gziaIEmZ8kZU5kWuZHf12v4HfGzO5kTn8N6CV7XkELSb4h PqBPox982eyb3Qy1YL3lNjx+gXfIRhDFtFOdjE0I82j3BPPZqvRqT943JZJBmdzhpnzc WgMOqNGiLkRT9Ez5KHcBqwWypliSoXWNVs/kw/wxpdp1nxy7t2bjwWcWP9pUjWLHHqSz cKiXkZBwweOSw76tEKzdiJs2/IA7AHDZRotvTqdBHdraWaA/o8BlMMQtMaiM3InsVoad AnG7HZu2/0MskVZhJhyDbZaLf3H3T71kPYMfZexKTaSVLYYGhwZJIL5AFq92gqzWSThP ETaQ== X-Forwarded-Encrypted: i=1; AHgh+RoGy3hJX5m/sCMMkTfBLDb53QUNb6ckHpM87x+vRlsbNXQlVLweR7cV7ZNyAJDLJEgUc02TMiMLfckERog=@vger.kernel.org X-Gm-Message-State: AOJu0YxaY9n5I+sSDG9cLK18GgRR5bF7GNLtEWgwqLXr7IjfVioQ3K1h 63mZmC0Inc1OvwQ15BAHijCf0JW2BDfXQtauNbRPs1fvOQiWkMciRa0UbcEQOYJNCx+nefEvh8r NBqNNgSZWkhedJkcgEw== X-Received: from edgd22-n1.prod.google.com ([2002:a05:6402:a516:10b0:6a0:d334:54e7]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:e15b:20b0:c21:3c4e:cb9d with SMTP id a640c23a62f3a-c213c4ecd42mr205334666b.14.1786741260571; Fri, 14 Aug 2026 14:01:00 -0700 (PDT) Date: Fri, 14 Aug 2026 21:00:55 +0000 In-Reply-To: <20260814210057.4102768-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814210057.4102768-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814210057.4102768-2-tarunsahu@google.com> Subject: [PATCH v3 1/3] ARM: locomo: use put_device() on device_register() failure From: Tarun Sahu To: helgaas@kernel.org, dmatlack@google.com, Nicholas Piggin , Greg Kroah-Hartman , sourabhjain@linux.ibm.com, "Christophe Leroy (CS GROUP)" , Pasha Tatashin , Russell King , radheys@amd.com, skhawaja@google.com, djeffery@redhat.com, Geoff Levand , Madhavan Srinivasan , Michael Ellerman Cc: linux-arm-kernel@lists.infradead.org, souravsgl@google.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Tarun Sahu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As per device_register() function kernel documentation says "even when device_register return error always use put_device() instead of kfree()" Fix such instance in locomo driver by replacing direct kfree(dev) with put_device(&dev->dev) when device_register() returns an error. Signed-off-by: Tarun Sahu Reviewed-by: Sourabh Jain --- arch/arm/common/locomo.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c index 55e360452828..0f6689d343b0 100644 --- a/arch/arm/common/locomo.c +++ b/arch/arm/common/locomo.c @@ -223,10 +223,8 @@ locomo_init_one_child(struct locomo *lchip, struct loc= omo_dev_info *info) int ret; =20 dev =3D kzalloc_obj(struct locomo_dev); - if (!dev) { - ret =3D -ENOMEM; - goto out; - } + if (!dev) + return -ENOMEM; =20 /* * If the parent device has a DMA mask associated with it, @@ -255,10 +253,11 @@ locomo_init_one_child(struct locomo *lchip, struct lo= como_dev_info *info) =20 ret =3D device_register(&dev->dev); if (ret) { - out: - kfree(dev); + put_device(&dev->dev); + return ret; } - return ret; + + return 0; } =20 #ifdef CONFIG_PM --=20 2.55.0.691.gc56d675ccc-goog From nobody Mon Sep 28 23:55:27 2026 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 BF92A349CF3 for ; Fri, 14 Aug 2026 21:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; cv=none; b=myhpdoiKsEfIZu7mibVPTKNScS/ZvLjcWN4Uym5hrLwjgkcbG4tZ6vPKeEN1jlmX/0PEtQY+n+T8l4fEkLRMEq4TGaDwgguwoiCXIk0YIUKbroJm6dNzDfw1ZT1PGzu5hj0vDpUA2BGyZ0sQA764jjwXOkHytVP8Zn0UZfGhTmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; c=relaxed/simple; bh=M9BEDwEaTA9Aidy34tdCH0UUxPsZswww+McR6MmL6kI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rhAygIYqQBP5ganJQmTswufsv7i+MQq1GAD2zXUko7TrMu2PyINvnLS7mu8W2Lk19QsDjUCWWGGPs1w0nL3z97HevCY5WPUdvUpD89X+/jq7/n5sWm8sB70hx0Ri7PX8p0Bq1U9+bl0vu63gCfH02lux1LkxP5tPzK5rzVOWLQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hpKTNwm9; arc=none smtp.client-ip=209.85.218.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hpKTNwm9" Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c1f548718d0so154724566b.0 for ; Fri, 14 Aug 2026 14:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786741262; x=1787346062; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7b9OMXuv3ZP+H19/AmnDH9qKEt9RkVpbpVuxQpQ0/a8=; b=hpKTNwm9dU/zJVgXsBLp0Z8k5gXDaiaVyWwJWiAEAJI6QV1nHB6wB5lwwPcqdgFAqB MKyc1lJTGP2p0DlWFhsfimIRgdl59ixVS62ewjl6mvG5/DFqHCkassxv+uClJUr9GqaL GpD5SPadYPIQp6Aj7yReNAgYpB59ab3gPeOsiavM5ZzKBQZdd+fQCkDoIezwpyuh1+Ag lId281gMQN+NG5xxkPMRmPct5FRyen/6N+gaJittqTjrv9TuOFM3pxChRV3/GT61tmfR GLu0RwaQMx6oIc8h6dg82JuWWA5qMEWpWjqUwEDyEdAyxxfyplryiHKB0PvLjg0OvaoS 1SAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786741262; x=1787346062; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7b9OMXuv3ZP+H19/AmnDH9qKEt9RkVpbpVuxQpQ0/a8=; b=g2qIjzVOeG5cwDzdkvgIShzvMdQPI7kT3E/1NSoVUrIFVRsVB7N9DMXkta3YmLiD6Q IZX+m5e3lb960eW0lVY4PRoTXJaansxm5ox/3KhLgUM5iNXcqF0x+B1E0+/kJ273tQ2T QZaJYTnIP2zmxZYC2q2VZWN6ov2LoFAiSvs8P8OVloo3RZndRmoJium8W3xIeUNSPSoZ DKkkdsP0kPlWL3c/qM1Beg/Qrr5ZfSgloFcn3AxAOD2fxWNlzCzLWlaZx9r2xHLz8Pmx f7hv2XPFK54JRBj9AY4fn5Fh9duUI9JLd1xCUc4j+hjoAR0IKfx9ewosbMUuzjjqLbPG 3VPQ== X-Forwarded-Encrypted: i=1; AHgh+Rq8lN96a7dXjHN4LVgCPs+DXQ3coPyT21rDuJdSBIFSFVVkwPJ8kCKt7kA9aA4j7CBxPfW89ROJxbl1Q9w=@vger.kernel.org X-Gm-Message-State: AOJu0YzqXw+ONMpj+CfmoCxQi8x5VLu12R1KFyfHjEr9dXJVEEOO4W4b sognGiUBU8wO4Xl8U+slAVVFyR7EUMoXEXiTIX96K1/k80vJ6YDil4kiPhFVISa/FUSR9pZ/mcN 2U0XgEfTlqnJ9xWQkIw== X-Received: from ejcfz27.prod.google.com ([2002:a17:907:959b:b0:c09:e2fc:4344]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:a606:b0:c1c:2007:298e with SMTP id a640c23a62f3a-c212a208e62mr387287766b.24.1786741261643; Fri, 14 Aug 2026 14:01:01 -0700 (PDT) Date: Fri, 14 Aug 2026 21:00:56 +0000 In-Reply-To: <20260814210057.4102768-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814210057.4102768-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814210057.4102768-3-tarunsahu@google.com> Subject: [PATCH v3 2/3] firmware/edd: use kobject_put() on edd_device_register() failure From: Tarun Sahu To: helgaas@kernel.org, dmatlack@google.com, Nicholas Piggin , Greg Kroah-Hartman , sourabhjain@linux.ibm.com, "Christophe Leroy (CS GROUP)" , Pasha Tatashin , Russell King , radheys@amd.com, skhawaja@google.com, djeffery@redhat.com, Geoff Levand , Madhavan Srinivasan , Michael Ellerman Cc: linux-arm-kernel@lists.infradead.org, souravsgl@google.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Tarun Sahu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As per koject_init_and_add() function kernel document, even if this function returns error kobject_put must be used instead of kfree. When edd_device_register() fails after initializing the kobject with kobject_init_and_add(), calling kfree(edev) directly bypasses the kobject release callback (edd_release) and leaks the allocated kobject resources. Fix this by replacing direct kfree(edev) with kobject_put(&edev->kobj) on registration failure. Signed-off-by: Tarun Sahu Reviewed-by: Sourabh Jain --- drivers/firmware/edd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c index f980c5b56858..763e7b16d517 100644 --- a/drivers/firmware/edd.c +++ b/drivers/firmware/edd.c @@ -748,7 +748,7 @@ edd_init(void) =20 rc =3D edd_device_register(edev, i); if (rc) { - kfree(edev); + kobject_put(&edev->kobj); goto out; } edd_devices[i] =3D edev; --=20 2.55.0.691.gc56d675ccc-goog From nobody Mon Sep 28 23:55:27 2026 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 C4A343E2AB7 for ; Fri, 14 Aug 2026 21:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; cv=none; b=pNdVu1RDwlg1RwLEcEv29lyQMrbjs9BwH+1iESMINP4JGORz+b9akB1U4dATnQDCg9r8ef532RLiQ1/KFLf3ciWWwhq34DoplpMEdqiFb0QHaq/eJ6rP73E8C5QZWuMIW76CrBm04ODKefYrEcbK3gbXSnWTIfQmTwCXQdyp4UQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786741270; c=relaxed/simple; bh=aTDo7K5yfUTVx+oOHJM4HYcYLv6twqXtO1fJdJ8qHcI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HXq7d1rjBmrEPY33HxX9hNawhVhi5JLxRcYX2wBJi7Fz4+zbyFvXen4HR/synrG30w6Oy7MMd68B7da32CBLGOXDtuuf1y1EA1SPu0a0eLLzlth4xe0J4wloie0pzw8b8IOCO0I+ZicS9B0slJiwDFpIDJn9UAFRYpK4cskDozE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jK55epq+; arc=none smtp.client-ip=209.85.218.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jK55epq+" Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c15d4bd2afeso119209266b.3 for ; Fri, 14 Aug 2026 14:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786741263; x=1787346063; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MLg3iB6Pagz28XpVaRBy9ZM+C4ap5o/b/rz1etSQnGM=; b=jK55epq+Ibg6FbqSIV33rVA1zbz/huIXUHe5oNAPjymDc5CxVBomIhjJPG4Tu7Nwdg oVaHq0Qg9kr3hbE3qSzjO5jTfnC2X7j/T2m8TAmYdFicth6PvI+32FeDWowOroSUEDSW J9SMfesM6kFnE0Ld3m24kTvzi0WlNLGOC/SLJ5Trazn/vEo90xKzs0OfVUlxHSoKzWy/ G9zMstPv5L1rA20SyzgH7c0cImqZqfqqyrRqYvlZNbw9VPHd5BqDieSnagWv5cjhJiZK 2loaiK77o2wnYsCegoQJLppvKpofNyOHItOgG7ZI3QlSuZPVczTyUo8GPvGcFPf+fP18 elxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786741263; x=1787346063; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MLg3iB6Pagz28XpVaRBy9ZM+C4ap5o/b/rz1etSQnGM=; b=ng1o//f1LAxMNPSAb2hBIH5ENkCDR9tKuf9NpwAs5zEyg1R2FKYI768wleHqojp3LU X2nn8G4xUpCgxPWGyDn4VAJllgcm6wEXGxB+Kl9XDgztabCi8I3E2Qx8PnVefp59kbQg vaWYCY1K4jlQ63PeAOxnf7pPDWmdZAkYjP5OWOEXdR5ONUjDTSB751bW+CKfd22gCApj QI4owtvyd4zH65GTcHe1YwvB+K744H0WxL19SjN3pFZPIrLRNDtmMvnaQK73FHrHYY3f 0xt3PK21ZQWmAkIgcywgQtZq4+H71BC6LCKu7FhhAgvLXY3oQk7YpGEK2oiPLf2pZBqR luBg== X-Forwarded-Encrypted: i=1; AHgh+Rpewq100Y/MlU/MTrAW+yIl6p0vcm+AH+taG6fFKtVBVyqGZHfO9dhotoBho4+TTjby3PQAj4y7N7FZF1M=@vger.kernel.org X-Gm-Message-State: AOJu0YwV+pf8Xz8N8Pe+XdWKhlTNglXCq8QL0DrkmKLtFowQNZgLHJqm 9Jny8/0LMHvq6uiGsNxr1+cJUZw6gbrdgpW1g54eWRGrnwwNlfNxI0APIQ7cNSq6X2UciJMlQeo BpT9LtBCsUHudehmavg== X-Received: from ejcyh20.prod.google.com ([2002:a17:907:e894:b0:c20:282e:ae3d]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:99c1:b0:c15:a487:3482 with SMTP id a640c23a62f3a-c212a8f7432mr355541166b.21.1786741262708; Fri, 14 Aug 2026 14:01:02 -0700 (PDT) Date: Fri, 14 Aug 2026 21:00:57 +0000 In-Reply-To: <20260814210057.4102768-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814210057.4102768-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814210057.4102768-4-tarunsahu@google.com> Subject: [PATCH v3 3/3] powerpc/ps3: use put_device() on device_register() failure in ps3_system_bus_device_register From: Tarun Sahu To: helgaas@kernel.org, dmatlack@google.com, Nicholas Piggin , Greg Kroah-Hartman , sourabhjain@linux.ibm.com, "Christophe Leroy (CS GROUP)" , Pasha Tatashin , Russell King , radheys@amd.com, skhawaja@google.com, djeffery@redhat.com, Geoff Levand , Madhavan Srinivasan , Michael Ellerman Cc: linux-arm-kernel@lists.infradead.org, souravsgl@google.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Tarun Sahu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As per the kernel documentation of device_register() function, it is important to call put_device even if device_register returns an error. To follow this guidelines and properly release the resources after device_register() failure, call put_device() instead of kfree() Also there are in-function-defined struct layout which make struct device (core) to be child of layout-child's member (layout.dev.core). Also definition of struct layout is not unique across functions in the driver. To be able to free struct layout's dynamic allocation via put_device we need to make sure that the core's release function must call the free on parent of core and the parent must be at the location 0 of the struct layout which will inherently free struct layout. This is to not complicate the code and keep it as it currently implemented. To check the location of parent at 0 of struct layout, I have added BUILD_BUG_ON. Signed-off-by: Tarun Sahu Reviewed-by: Sourabh Jain --- arch/powerpc/platforms/ps3/device-init.c | 83 ++++++++++++++---------- arch/powerpc/platforms/ps3/system-bus.c | 2 + 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/platforms/ps3/device-init.c b/arch/powerpc/platfo= rms/ps3/device-init.c index 9109c218a060..8d0c77db1764 100644 --- a/arch/powerpc/platforms/ps3/device-init.c +++ b/arch/powerpc/platforms/ps3/device-init.c @@ -90,14 +90,12 @@ static int __init ps3_register_lpm_devices(void) if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_register; + return result; } =20 pr_debug(" <- %s:%d\n", __func__, __LINE__); return 0; =20 - -fail_register: fail_rights: fail_read_repo: kfree(dev); @@ -121,6 +119,12 @@ static int __init ps3_setup_gelic_device( struct ps3_dma_region d_region; } *p; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d\n", __func__, __LINE__); =20 BUG_ON(repo->bus_type !=3D PS3_BUS_TYPE_SB); @@ -164,13 +168,12 @@ static int __init ps3_setup_gelic_device( if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } =20 pr_debug(" <- %s:%d\n", __func__, __LINE__); return result; =20 -fail_device_register: fail_dma_init: fail_find_interrupt: kfree(p); @@ -192,6 +195,12 @@ static int __init ps3_setup_uhc_device( u64 bus_addr; u64 len; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d\n", __func__, __LINE__); =20 BUG_ON(repo->bus_type !=3D PS3_BUS_TYPE_SB); @@ -252,13 +261,12 @@ static int __init ps3_setup_uhc_device( if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } =20 pr_debug(" <- %s:%d\n", __func__, __LINE__); return result; =20 -fail_device_register: fail_mmio_init: fail_dma_init: fail_find_reg: @@ -291,6 +299,12 @@ static int __init ps3_setup_vuart_device(enum ps3_matc= h_id match_id, struct ps3_system_bus_device dev; } *p; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d: match_id %u, port %u\n", __func__, __LINE__, match_id, port_number); =20 @@ -308,15 +322,10 @@ static int __init ps3_setup_vuart_device(enum ps3_mat= ch_id match_id, if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } pr_debug(" <- %s:%d\n", __func__, __LINE__); return 0; - -fail_device_register: - kfree(p); - pr_debug(" <- %s:%d fail\n", __func__, __LINE__); - return result; } =20 static int ps3_setup_storage_dev(const struct ps3_repository_device *repo, @@ -327,6 +336,12 @@ static int ps3_setup_storage_dev(const struct ps3_repo= sitory_device *repo, u64 port, blk_size, num_blocks; unsigned int num_regions, i; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->sbd). + * sbd must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct ps3_storage_device, sbd) !=3D 0); + pr_debug(" -> %s:%u: match_id %u\n", __func__, __LINE__, match_id); =20 result =3D ps3_repository_read_stor_dev_info(repo->bus_index, @@ -395,13 +410,12 @@ static int ps3_setup_storage_dev(const struct ps3_rep= ository_device *repo, if (result) { pr_debug("%s:%u ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } =20 pr_debug(" <- %s:%u\n", __func__, __LINE__); return 0; =20 -fail_device_register: fail_read_region: fail_find_interrupt: kfree(p); @@ -445,6 +459,12 @@ static int __init ps3_register_sound_devices(void) struct ps3_mmio_region m_region; } *p; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d\n", __func__, __LINE__); =20 p =3D kzalloc_obj(*p); @@ -461,15 +481,10 @@ static int __init ps3_register_sound_devices(void) if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } pr_debug(" <- %s:%d\n", __func__, __LINE__); return 0; - -fail_device_register: - kfree(p); - pr_debug(" <- %s:%d failed\n", __func__, __LINE__); - return result; } =20 static int __init ps3_register_graphics_devices(void) @@ -479,6 +494,12 @@ static int __init ps3_register_graphics_devices(void) struct ps3_system_bus_device dev; } *p; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d\n", __func__, __LINE__); =20 p =3D kzalloc_obj(struct layout); @@ -495,16 +516,11 @@ static int __init ps3_register_graphics_devices(void) if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } =20 pr_debug(" <- %s:%d\n", __func__, __LINE__); return 0; - -fail_device_register: - kfree(p); - pr_debug(" <- %s:%d failed\n", __func__, __LINE__); - return result; } =20 static int __init ps3_register_ramdisk_device(void) @@ -514,6 +530,12 @@ static int __init ps3_register_ramdisk_device(void) struct ps3_system_bus_device dev; } *p; =20 + /* + * ps3_system_bus_release_device() calls kfree(&p->dev). + * dev must be at offset 0 so kfree() frees outer p. + */ + BUILD_BUG_ON(offsetof(struct layout, dev) !=3D 0); + pr_debug(" -> %s:%d\n", __func__, __LINE__); =20 p =3D kzalloc_obj(struct layout); @@ -530,16 +552,11 @@ static int __init ps3_register_ramdisk_device(void) if (result) { pr_debug("%s:%d ps3_system_bus_device_register failed\n", __func__, __LINE__); - goto fail_device_register; + return result; } =20 pr_debug(" <- %s:%d\n", __func__, __LINE__); return 0; - -fail_device_register: - kfree(p); - pr_debug(" <- %s:%d failed\n", __func__, __LINE__); - return result; } =20 /** diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platfor= ms/ps3/system-bus.c index 0537a678a32f..0918c74d3e19 100644 --- a/arch/powerpc/platforms/ps3/system-bus.c +++ b/arch/powerpc/platforms/ps3/system-bus.c @@ -774,6 +774,8 @@ int ps3_system_bus_device_register(struct ps3_system_bu= s_device *dev) pr_debug("%s:%d add %s\n", __func__, __LINE__, dev_name(&dev->core)); =20 result =3D device_register(&dev->core); + if (result) + put_device(&dev->core); return result; } =20 --=20 2.55.0.691.gc56d675ccc-goog