From nobody Fri Apr 17 20:22:44 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 4E92E23370F for ; Sun, 15 Feb 2026 22:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771194247; cv=none; b=G/ncqHxtqsIWX6+vFM11qP8oSDx+PTb93SodOuTJIRHTzOtvhcyE7vugw7q87W6Y0JUd0PLTJFKM8+ZczweEVF5FeVgTgIpAW4DIZuuEB2ltH6IIHA8Astg12HFrMXKLTcNpSypOnP42o4TXkpgEW2KS0tgl4QnzlmZeB0MZUGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771194247; c=relaxed/simple; bh=rDzme/Q5Rl0/Ur4R6FppbNBFAQBVwz+8CH62eaR53k8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=E8yV0NtXt+X2VgotKuJgsC7YxNpn5QKbMS29QQ9whgE0CGB5dNZ2fV3qWeIxHx5bSYg8Z1lD5l5+e1r96oXJ33uxoipM2qLX6rbsGUa732dbsJtmUwRb6bTsuhtif6SffAcyw1y2q3MZH8aGC6jbHC2iT76irSWL5WZXhqB/OV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Sy2HlMpK; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sy2HlMpK" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-48370174e18so16467355e9.2 for ; Sun, 15 Feb 2026 14:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771194245; x=1771799045; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=66Vmwy4Sh5Yol6CcoKobP9N7ecyBQmrCDQEcpTKoAGI=; b=Sy2HlMpKXKD35HWh/3dFf/GpoafnrAJgAQRWQ4H82zdxDYM5ojJtxFUmbqGZq2F9r4 9KOO60fOmJ/FTYFMeygAZqYyi7HeScSvltkRJwppMD9BGS/HEUqjNuvrpBax98vPmH3c s1FybGQULcEvyRVyCxUuBJYZcBQb0dvulNa/HVAUsEKsu7i+mWgLKaMPzhgaWahtXm06 T67oI1yuoEs/mEAdKIrppUzNmkAeMTPvSn7ckuj6g+L7AQH+klUncJZG2IS1mt8YOHHX 3DWHo8LBJvQV56n9qIXHwcGnUU9meMswirH0YZqqiDgf3uCXjhKwlQgzHVLyOE8Li9PK rulA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771194245; x=1771799045; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=66Vmwy4Sh5Yol6CcoKobP9N7ecyBQmrCDQEcpTKoAGI=; b=ZofWa8NA5vC+wGEjkeQSEavZf4eiSeLZ/IMc09fAB0YXXG46mtM1Su0SUntiK66/yz zfr+RjrfMBQ7fq0CM5OwgloDm+BncY5DSvyfXVCFYlNMLQUm/eeuLKBmM5JNCYeSHFxF XZxbCdDD4jOmHOj1nLRL0Tk+CfYjCiPhJqwhKqb8WeRdLvBkQZHR7xDsQPAka2WFL2Le wIJclSJYVEPoLCwzQal1Sm0LdIQJnbwIjZbe3ZvB2viKpJuKiE1k7hSYzHizziMZ6GDe BF7jw8q6qaDC1BHL/r89DnhiOjtDfzK2RvFLuI3zm+iASHpEXZw+Musn0CVepaDXLm0p Aiug== X-Forwarded-Encrypted: i=1; AJvYcCXkkkWRgLFH4NZuuTu0NpLM/U3daiNCFeDxRv7Suimfd4JW6yOPDKlybXO0Ni6k89fij1o/cHbHVoai3lU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9J5IgUw+/fnc8G7+kA3pWk71bsByCvXTEPxhA5fqtd1ZziAVz siE0ha7mTCHBZiOBP8mfPfBpzmt/fg6C+ev9LsqfVKSuHEeUQhKu+zwO X-Gm-Gg: AZuq6aJuI/8f8Sh46tE5Zt3ae8KZw/8xTk158W/ScolHrDeRfR2UQ9iEGpviEjrbxKD y+2lgwlMUY7c8UtEguHjjI11TkQ/NHfEEZjT/ZIuKSmwmVifHSlLL+VrMRPVadJxqhLpTwAgbdx GvjZVZ8fCsyyTQnF7QB8PEHdZ4Oaor5b4BhAB/FKnyYXsLGvwHMlxGU/2cRvEPZTnWzU3jhG1iV rkRxLWYFmCKkDaAfOR8fS2X20sQipbDSeM0FmMd5SAjaoH3rCE9gCwkYuHwigvstXed16mj0z/K GjxP9Apu11JiTYWx1jwE+I51lHtEmfjzNXaCE8Jk5asgbEi25CK47/C1k6lMqjqA/MnODxn/Wx5 yJBnkqFV0AkTZZ0LmJyxdvEoLViL9/wy3Uuh1YWoQkE6ky0fiX0F4GrEErI4U3rN2/WenMzAtXm 02nYh0eALTWbghGTev9Q8QOspNpv4QksyTYs1N X-Received: by 2002:a05:600c:5285:b0:480:1dc6:2686 with SMTP id 5b1f17b1804b1-48379b990fdmr103216285e9.13.1771194244437; Sun, 15 Feb 2026 14:24:04 -0800 (PST) Received: from localhost.localdomain ([196.235.85.27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483709f8812sm124548495e9.0.2026.02.15.14.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Feb 2026 14:24:03 -0800 (PST) From: Salah Triki To: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Salah Triki Subject: [PATCH v3] iio: trigger: use put_device() in viio_trigger_alloc() error path Date: Sun, 15 Feb 2026 23:23:47 +0100 Message-ID: <20260215222348.186806-1-salah.triki@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Once `device_initialize()` is called, the lifecycle of the trigger must be managed by the kobject reference counting. Currently, if `kvasprintf()` fails, the code manually calls kfree() and `irq_free_descs()`. Switching to `put_device()` ensures that the device's release callback (`iio_trig_release()`) is properly invoked. This simplifies the error path by centralizing the cleanup logic (including `irq_free_descs()`) inside the release handler, following the standard driver model pattern. Signed-off-by: Salah Triki --- Changes in v3: - Rewrite commit message to focus on standard design patterns. - Remove the "Fixes" tag as the change is a cleanup/robustness improvement. - Simplify the description of the fix as requested by the maintainer. - Change title to better reflect the change (not a use-after-free). Changes in v2: - Remove the manual call to irq_free_descs() in the error path to avoid a double free, as this is already handled by iio_trig_release(). - Clarify the error path and the potential for memory corruption in the commit description. - Remove the blank line in the tag block to comply with kernel script requirements. drivers/iio/industrialio-trigger.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-= trigger.c index 54416a384232..7f53e2a5a101 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -576,7 +576,7 @@ struct iio_trigger *viio_trigger_alloc(struct device *p= arent, =20 trig->name =3D kvasprintf(GFP_KERNEL, fmt, vargs); if (trig->name =3D=3D NULL) - goto free_descs; + goto free_trig; =20 INIT_LIST_HEAD(&trig->list); =20 @@ -594,10 +594,8 @@ struct iio_trigger *viio_trigger_alloc(struct device *= parent, =20 return trig; =20 -free_descs: - irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER); free_trig: - kfree(trig); + put_device(&trig->dev); return NULL; } =20 --=20 2.43.0