From nobody Fri Apr 17 09:18:13 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 8A0DA1F419A for ; Sat, 21 Feb 2026 07:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771659198; cv=none; b=VuRqf4AinXHr5T6OZAmVlU/tBj2gkHdx/WnjAKvQghssk5vAjtJA0+JpEolJ3rX4/qvrQKPIJ39RNt1lgQTHj0kAQiA999q/NeR6pU4/J+9vglZrFEmB8EOeZS8C1GdPcGc2yyHKfJOBhWs/AmDoYtpWRZ2Mux4IelhGzWEbOGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771659198; c=relaxed/simple; bh=JBLp57T2rH1A64A7q8apja8cyBEzsnE2qvklYDn1YJ0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=K8ATqyMRjZZJZNdpraHow7Vc4AhLEE29pIa6OMQuZ6j/OIvWLk+dY0Bugfhd47lU6sAKHlzxcceDw4cvAXdD+6pBwCXd1Ss4RowlzbW3GXz5K+MHfmr087oBjU4+LsleYp8DzvZNvDQmQbfghOMmMBnv3lDcRH678LIoOzwad2I= 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=hNn03214; arc=none smtp.client-ip=209.85.221.42 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="hNn03214" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4359228b7c6so2138285f8f.2 for ; Fri, 20 Feb 2026 23:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771659196; x=1772263996; 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=DIDvOyw8CGCfP65CRhRJUSgrBkLbuDLQEI5t55r/3B4=; b=hNn03214BnPZM8zDQA2OWXjaTm6kROnGpAqXfahWbXiTeq13zAwu9fsbnK1IvjCZ8g GSsjgvQsVD0nhnI+PpVUbwN73rcDtr1vrw/gstrlcX2utXUDku2CBIiHi4rricJIOPHe gNEeKvKvC/u/x2WbesWdVOmVQdI4aSHH1epik6m0g6XmYT0JOj4yKDLdk9UXcwhFi6Ib ra+WUTT2b90gYvAVyZEtkej44IJYXQU/FEbKV2803zzNijTnM/W2xnjo1AoZ44Kvlnhs kgkNp2jJ0iD9bCfb2k+Mm6OPNCYglkcLgJ8n2O9KbFCp2dxpx/0TAmL0Eu+u2EZXAKEG uUdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771659196; x=1772263996; 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=DIDvOyw8CGCfP65CRhRJUSgrBkLbuDLQEI5t55r/3B4=; b=WwFjY+mtCdbzMfecU3T00d0HF2Ikx97iGUObplB+AxgxxyyZQxkeUBWaLr8vIRdBQt 66xHEoA1MVyUiG2EGuoiginxtG43itjX/L9WVlOvxCd+5C+5BaiGSl0parjOuRlZBpkl 7cfsE20Z9LbdB6t3g66D27PT7zsJ03kppbcmaqW7QzptRjS6gjTk9/dRKYy+3XS66h5l 7xAZ7pcqJJuXz7/0EDUgEDyjCqn+Jj8+ZvmP6Z8NHKtQmJWuHW5ctHseovBnilq+R1jL LN9bo9tOWUV1/EicDmMwdcFqYxRWaiMATHwagBAkeiTKVSOc4pNflJTE0QH2pESyZenZ AfIQ== X-Forwarded-Encrypted: i=1; AJvYcCXrNJgP/48FH3ynxl24vLG7Oilf9q/Q8Ai7a+Y+Xqscohopm7YvEed3O8T68lTGNfQm4NoU1KLKeGX+iq4=@vger.kernel.org X-Gm-Message-State: AOJu0YxuEx1Oaf2bhivFbvIFYk2dxYkgEyRE2RNVEV8yhdntocwm4xMV fRq+lbQjN7JrxvOVm45oo5GNOdLtrXRKdXDkB7bf73q3shNQ1YPB1LlK X-Gm-Gg: AZuq6aJ6IaUZrt9iP99vUaOXLfs12NZpjy5tKrUArm3tS8HIeZWrA9hEaeoiXY5vW+s fwdf1hXHE6aRRbVRy3sZN8Pe1Wh6gkCXJ49k/z/dfb/VOEzaWS613kBILQnhe/BG7HvwKLzukbZ gOLtI5fs1EuVJV8RajVY/Q7tzk6J+c2aR6np1zox/40NpCib3QtArupdsZ1MO9LBbL2NfQdOwl5 JmZHcrL3uEcUXeSrUm9EvLDx8Anqe8x9dvZ5jCiIwsemDaFuVUgR5icUcPro4eXNHh/8HjqaWcw /dPb6O5rK6J8mv0p57DhaBvH3TCHeBq4UeJptW/Ncn131J5QfxaVjCOT+C1bnbfmLzySPpBrkFp ZglWxszy/LNL6ZhSlsCySDVWgSGxuWMlpbPxuyo1XGAG4ePKTP4Obdr5rwJZJ2DuMhsv7wozIT2 LP/frN8q0aokj35tG49sLf8Lhfnt1S0qsE5W95rRY= X-Received: by 2002:a05:600c:6296:b0:47a:81b7:9a20 with SMTP id 5b1f17b1804b1-483a95c6774mr35319915e9.9.1771659195647; Fri, 20 Feb 2026 23:33:15 -0800 (PST) Received: from localhost.localdomain ([196.235.238.153]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483a31f0330sm103093365e9.9.2026.02.20.23.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 23:33:14 -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 v4] iio: core: Clean up device correctly on viio_trigger_alloc() failure Date: Sat, 21 Feb 2026 08:32:42 +0100 Message-ID: <20260221073301.105080-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Once we called device_initialize() we have to call put_device() on it. Refactor the code to make it in the right order. Signed-off-by: Salah Triki Reviewed-by: David Lechner --- Changes in v4: - Move device_initialize() after all potential failure points (kvasprintf a= nd=20 irq_alloc_descs) to avoid premature lifecycle management via kobject. - Revert the use of put_device() in the error path and use kfree() instead,=20 as the device is not yet initialized. - Align the implementation with the pattern used in iio_device_alloc(),=20 as suggested by Nuno S=C3=A1. 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-= trigger.c index 54416a384232..c995311bf699 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -561,10 +561,6 @@ struct iio_trigger *viio_trigger_alloc(struct device *= parent, if (!trig) return NULL; =20 - trig->dev.parent =3D parent; - trig->dev.type =3D &iio_trig_type; - trig->dev.bus =3D &iio_bus_type; - device_initialize(&trig->dev); INIT_WORK(&trig->reenable_work, iio_reenable_work_fn); =20 mutex_init(&trig->pool_lock); @@ -592,6 +588,11 @@ struct iio_trigger *viio_trigger_alloc(struct device *= parent, IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); } =20 + trig->dev.parent =3D parent; + trig->dev.type =3D &iio_trig_type; + trig->dev.bus =3D &iio_bus_type; + device_initialize(&trig->dev); + return trig; =20 free_descs: --=20 2.43.0