From nobody Wed Feb 11 01:27:47 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 C2D45346E58; Wed, 12 Nov 2025 14:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959463; cv=none; b=RFxfetxlTkMRHZAnGF2SIupZ7l36BZDPySNRXMKkxEOApIydTaBhGqX0kPpAFEyL/RVNUHyvYBxHDo2QlKvW22FsCA9x9KQIfXlp2vKhXiiMuqtF0Boptbh2AesYpUibz7063elGEEgtvAvdRhh8SO8soIoNJEk0TJvzDwIIQn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959463; c=relaxed/simple; bh=igzg+SgGyMnbqCojYaqGL+0t/DAUq1ocYpBoPxC7Ko4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ogm4EWCjrfS+NeJipIZBDb2ub+yLw5az5V7fOVPjgFK7BQKIuF8g8mQge32AhZsdvfuT7tsHBstIVXjH7hln6/veqvVU1h5EkBCRdLKsRbk0j72GE3ts/zZoxgxVwih0asSZVxwgv5eQjITi+pfLDfWfo2X1AvyOa4foQ01+Y0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Qzx54ikB; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Qzx54ikB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762959461; x=1794495461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=igzg+SgGyMnbqCojYaqGL+0t/DAUq1ocYpBoPxC7Ko4=; b=Qzx54ikBxmdnc52ryUoB1smrsr7IgpQZ/3HSD9PH31HYM/edSLCLliLh k6yttJQuWCdmt7wP9nTKtU+zn42D5IjgOUDju16dPA6FwqQaXMdzHWBPT Gs20AnuEXpm7BOkdlRPpllNyHQvXtCetdcEMQlt6qIx/eeofG4eef4deV utpauYzSoAzZV+MN4MDl4zkLP7uzUYe8+wL/6h6GaWizKq3L6tpvSbNbU I/ShZbY/5sLlJftXl+AOrX5Sr0EgJjt+oFMRCfiXNFKS0I4liE83Y813M hrE3Yyk1El0jCCfktyWULbfnHLUdGQCV3DXTX78q7Smz6q4+9KNZTeP0o A==; X-CSE-ConnectionGUID: TdSYsctmTfiLevErmHCA7g== X-CSE-MsgGUID: 5KGMhpJfQKW80B2vgc/VCA== X-IronPort-AV: E=McAfee;i="6800,10657,11611"; a="64728031" X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="64728031" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2025 06:57:38 -0800 X-CSE-ConnectionGUID: mBBSeF9USISFXGG3QWB+dg== X-CSE-MsgGUID: hINlLCbwQsSAi1BNT9b0/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="188874872" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa007.fm.intel.com with ESMTP; 12 Nov 2025 06:57:37 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id 24F0696; Wed, 12 Nov 2025 15:57:36 +0100 (CET) From: Andy Shevchenko To: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko Subject: [PATCH v1 1/3] iio: core: add missing mutex_destroy in iio_dev_release() Date: Wed, 12 Nov 2025 15:55:08 +0100 Message-ID: <20251112145735.2075527-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> References: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> 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" Add missing mutex_destroy() call in iio_dev_release() to properly clean up the mutex initialized in iio_device_alloc(). Ensure proper resource cleanup and follows kernel practices. Found by code review. While at it, create a lockdep key before mutex initialisation. This will help with converting it to the better API in the future. Fixes: 847ec80bbaa7 ("Staging: IIO: core support for device registration an= d management") Fixes: ac917a81117c ("staging:iio:core set the iio_dev.info pointer to null= on unregister under lock.") Signed-off-by: Andy Shevchenko Reviewed-by: Nuno S=C3=A1 --- drivers/iio/industrialio-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 88c3d585a1bd..93d6e5b101cf 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1654,6 +1654,9 @@ static void iio_dev_release(struct device *device) =20 iio_device_detach_buffers(indio_dev); =20 + mutex_destroy(&iio_dev_opaque->info_exist_lock); + mutex_destroy(&iio_dev_opaque->mlock); + lockdep_unregister_key(&iio_dev_opaque->mlock_key); =20 ida_free(&iio_ida, iio_dev_opaque->id); @@ -1698,8 +1701,7 @@ struct iio_dev *iio_device_alloc(struct device *paren= t, int sizeof_priv) indio_dev->dev.type =3D &iio_device_type; indio_dev->dev.bus =3D &iio_bus_type; device_initialize(&indio_dev->dev); - mutex_init(&iio_dev_opaque->mlock); - mutex_init(&iio_dev_opaque->info_exist_lock); + INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list); =20 iio_dev_opaque->id =3D ida_alloc(&iio_ida, GFP_KERNEL); @@ -1722,6 +1724,9 @@ struct iio_dev *iio_device_alloc(struct device *paren= t, int sizeof_priv) lockdep_register_key(&iio_dev_opaque->mlock_key); lockdep_set_class(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key); =20 + mutex_init(&iio_dev_opaque->mlock); + mutex_init(&iio_dev_opaque->info_exist_lock); + return indio_dev; } EXPORT_SYMBOL(iio_device_alloc); --=20 2.50.1 From nobody Wed Feb 11 01:27:47 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 841D2346E46; Wed, 12 Nov 2025 14:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959463; cv=none; b=E0cd7iAQLjgS9BwhfR+Cy26TLF3m69zbJQnQScTAUq0KKrxKIrxKD21yJ2lP/j4Ev0PUREN0WjXt3Cjx7r+HQqed2JZKfgwlmGfWQIcehaT3x59LDMMycCIoD94JfyZDB5fS2uDJZ5y2wWZnX8LEfLtK1TOu1hHFLXbgtiyazZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959463; c=relaxed/simple; bh=pYvFKKD4RrCAt43G3E8x50+Y+idteWAh5jNa5Ia/hIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a0CP1GGDSwVIX+5TkbTrTiy+GtwEDj+e5L3Ldfr37La+T0m8ACS33tB7k8F/1az+YIlP7evRsQeMnWQRDxuPhywwmrpN1bBbBdIeu8k+cgIpHFZ7/GMBnSnyEqKgNCdaaLMPUg9+2XBVAbxLmVzVQIQiRDQb08yDIskhZTqoPss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MSqcILE1; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MSqcILE1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762959461; x=1794495461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pYvFKKD4RrCAt43G3E8x50+Y+idteWAh5jNa5Ia/hIM=; b=MSqcILE1RdWn4qWv5IBDifmeBCBJHFeQcJQ/7SBOJOgpMKkz1d/dkPl1 AZo2EONc98inBl1WTjjtpXB2vG2/b7Ool95t6v8J5H8Cu7X6j4yaz+6X7 T1ittP7+tBnVtxGxV7FJRZpWQaOivYtTIpTyzc5Kkt+oG2Dtysf/RQqeE NOk/xk3MRrSs7Gm33CC4CPC3O/8Y8nHcmtN8r53T53z6mZ4wkYRKXrybq 59Pjfj3uuhDrHAPzAhHReDLdCK4h4o6/GzoT+G38cOBJr5viUsNM3MRT6 MwWcUGttz5XWM05aVces0jQ5vj9+3mrUnkUDrnw0d4hpioxB29RlCoQFO A==; X-CSE-ConnectionGUID: vrPti66AS6+JI4t9bHB2RA== X-CSE-MsgGUID: dsXjd++cSCak1ayNWfjeFg== X-IronPort-AV: E=McAfee;i="6800,10657,11611"; a="64728026" X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="64728026" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2025 06:57:38 -0800 X-CSE-ConnectionGUID: 4bq1oUjrT7iPAASnPCeSXw== X-CSE-MsgGUID: C9L1zFCQSJSZoFeRN3g+WQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="188874871" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa007.fm.intel.com with ESMTP; 12 Nov 2025 06:57:37 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id 28E9097; Wed, 12 Nov 2025 15:57:36 +0100 (CET) From: Andy Shevchenko To: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko Subject: [PATCH v1 2/3] iio: core: Clean up device correctly on iio_device_alloc() failure Date: Wed, 12 Nov 2025 15:55:09 +0100 Message-ID: <20251112145735.2075527-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> References: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> 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 we called device_initialize() we have to call put_device() on it. Refactor the code to make it in the right order. Fixes: fe6f45f6ba22 ("iio: core: check return value when calling dev_set_na= me()") Fixes: 847ec80bbaa7 ("Staging: IIO: core support for device registration an= d management") Signed-off-by: Andy Shevchenko Reviewed-by: Nuno S=C3=A1 --- drivers/iio/industrialio-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 93d6e5b101cf..5d2f35cf18bc 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1697,11 +1697,6 @@ struct iio_dev *iio_device_alloc(struct device *pare= nt, int sizeof_priv) ACCESS_PRIVATE(indio_dev, priv) =3D (char *)iio_dev_opaque + ALIGN(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN); =20 - indio_dev->dev.parent =3D parent; - indio_dev->dev.type =3D &iio_device_type; - indio_dev->dev.bus =3D &iio_bus_type; - device_initialize(&indio_dev->dev); - INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list); =20 iio_dev_opaque->id =3D ida_alloc(&iio_ida, GFP_KERNEL); @@ -1727,6 +1722,11 @@ struct iio_dev *iio_device_alloc(struct device *pare= nt, int sizeof_priv) mutex_init(&iio_dev_opaque->mlock); mutex_init(&iio_dev_opaque->info_exist_lock); =20 + indio_dev->dev.parent =3D parent; + indio_dev->dev.type =3D &iio_device_type; + indio_dev->dev.bus =3D &iio_bus_type; + device_initialize(&indio_dev->dev); + return indio_dev; } EXPORT_SYMBOL(iio_device_alloc); --=20 2.50.1 From nobody Wed Feb 11 01:27:47 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 7611A346E41; Wed, 12 Nov 2025 14:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959461; cv=none; b=YPPBCuh+jzyZ9PGbLZ9j6g3MI8VDygmPninz+3RZuy+psSDSIm4MW/yPIsUbixJqVo/7zi+E+oLFK+pVc63DZN6bkdqrP2Cf24mFYsplbSdbjgJ0KMVqX9tXrrvkkpt6URYmKlqFmMDBXF+kLMbzZJZxq992uT1XR8KJTh3FzGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762959461; c=relaxed/simple; bh=dzPIN1K4a2crXL9FdXtllClPyLCjvr+amLRN6CCJ9DE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHXje7MYDg67YF7mZz/ddKPj5rgxb9QZtuyP4MZLYuSHHkFJOLnOdj0hwByMjqVkXmekmR6EdiA1PlkUfhY4LHNixRtr3uIg4wu2inOGLnGcQY3sTcWTJW6Oaibe64wGPm4hacKors5AtIZu/ZaIj1XUaMBTGocT2MNf1+S1AmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hPgj24so; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hPgj24so" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762959459; x=1794495459; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dzPIN1K4a2crXL9FdXtllClPyLCjvr+amLRN6CCJ9DE=; b=hPgj24soos9MQ0bn94V+Ffm2mXCkY6Rq8qEbOB+1Kwp4X39SGYmsXE5Z px4vZlnyRErYhCCbB3c8YXlFoNJBaf8RjQ/HM4HPms4rTVxgXJCJ6hb4X yhyi4nMw5EijP7vBQ/GvtKZ6dAEX0DeoOsPyyTmBgAWClCZGwtYZPWXts oLuvcnDKXQZ+zK8w17D3Vel1T0fguOF6f9iJdeP70GQdjJ40dQCv/s3IK FEt6ILf7tRU/r9dQBQpCIPQfvEpO121WQQS3c60RAYPwRKHE1V8UKaZPj JabYxHD+oPe9Te0gXkLx6x/J2TJUYg0p5coLN/aFco1Bpl57FDDiTWWWR Q==; X-CSE-ConnectionGUID: DweKAa+IT3SNMpR2Sm7rng== X-CSE-MsgGUID: O2zy6zldTsaBY4HpBP3cTg== X-IronPort-AV: E=McAfee;i="6800,10657,11611"; a="64728018" X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="64728018" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2025 06:57:38 -0800 X-CSE-ConnectionGUID: 7mz2q09mQNC7ixwOcD8f/g== X-CSE-MsgGUID: h0CL+YTFTgSZ8gNpn7iqHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,299,1754982000"; d="scan'208";a="188874869" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa007.fm.intel.com with ESMTP; 12 Nov 2025 06:57:37 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id 2C87798; Wed, 12 Nov 2025 15:57:36 +0100 (CET) From: Andy Shevchenko To: Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko Subject: [PATCH v1 3/3] iio: core: Replace lockdep_set_class() + mutex_init() by combined call Date: Wed, 12 Nov 2025 15:55:10 +0100 Message-ID: <20251112145735.2075527-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> References: <20251112145735.2075527-1-andriy.shevchenko@linux.intel.com> 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" Replace lockdep_set_class() + mutex_init() by combined call mutex_init_with_key(). Signed-off-by: Andy Shevchenko Reviewed-by: Nuno S=C3=A1 --- drivers/iio/industrialio-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 5d2f35cf18bc..f69deefcfb6f 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1717,9 +1717,8 @@ struct iio_dev *iio_device_alloc(struct device *paren= t, int sizeof_priv) INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers); =20 lockdep_register_key(&iio_dev_opaque->mlock_key); - lockdep_set_class(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key); =20 - mutex_init(&iio_dev_opaque->mlock); + mutex_init_with_key(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key); mutex_init(&iio_dev_opaque->info_exist_lock); =20 indio_dev->dev.parent =3D parent; --=20 2.50.1