From nobody Wed Feb 11 06:53:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5A2BC76188 for ; Wed, 5 Apr 2023 15:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238467AbjDEP2e (ORCPT ); Wed, 5 Apr 2023 11:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237974AbjDEP2c (ORCPT ); Wed, 5 Apr 2023 11:28:32 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C8A5FC3 for ; Wed, 5 Apr 2023 08:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680708499; x=1712244499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JO0f1r6wRzpw2LpD2oOXpMFojPtpUquOfRT3bCgNfuI=; b=fZIEyajYax7/ymILgEkjfEufZs+1PvwVHM207kIjnGjiMKSNwugAOIWb tNrs3hQFCXSxrwBAf95CRaQSxak/i6IitU61qZDYcg3swvZXpCOKfmA// ktWCklVdBlMm1ll6O16GwWOF+EZ8lm61fAtBBpw4r/YyGpAuaS3cHY31f I7TpeLbL10+PwlpyoAZDnG7gPCCALTIqnYRviRwjt1D3Lxf//OgxAw+OB W38MtiTOILMbAO17ERKn4eLNfyer5oxLjpsW3Mc8RS6TCSr1nk4WXpHOq F2swCH1VL+Udj/zcrnqIfCp3vaEa06d0d0+bP6nb6Vp97XHhatvw6T28i Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="345064762" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="345064762" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:27:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="756028426" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="756028426" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Apr 2023 08:27:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A176F87; Wed, 5 Apr 2023 18:27:52 +0300 (EEST) From: Andy Shevchenko To: Chanwoo Choi , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham Subject: [PATCH v2 1/5] extcon: Make the allocation and freeing to be private calls Date: Wed, 5 Apr 2023 18:27:41 +0300 Message-Id: <20230405152745.24959-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> References: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The extcon_dev_allocate() and extcon_dev_free() are not used outside of the extcon framework. Moreover, the struct extcon_dev can't be filled outside of the framework either after allocation. The registration part, for instance, requires a parent device to be set and that's done in the devm_extcon_dev_allocate() wrapper. Taking the above into account, sumply move the mentioned APIs to the private headers. Alternatively, the pointer to the parent device can be added to the extcon_dev_allocate(), but since there are no users and magnitude of the change it makes a little sense to go this way. Signed-off-by: Andy Shevchenko --- drivers/extcon/extcon.h | 4 ++++ include/linux/extcon-provider.h | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h index 15616446140d..49e4ed9f6450 100644 --- a/drivers/extcon/extcon.h +++ b/drivers/extcon/extcon.h @@ -63,4 +63,8 @@ struct extcon_dev { struct device_attribute *d_attrs_muex; }; =20 +/* Following APIs allocate/free the memory of the extcon device. */ +struct extcon_dev *extcon_dev_allocate(const unsigned int *cable); +void extcon_dev_free(struct extcon_dev *edev); + #endif /* __LINUX_EXTCON_INTERNAL_H__ */ diff --git a/include/linux/extcon-provider.h b/include/linux/extcon-provide= r.h index fa70945f4e6b..db474ae3c711 100644 --- a/include/linux/extcon-provider.h +++ b/include/linux/extcon-provider.h @@ -25,8 +25,6 @@ void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev); =20 /* Following APIs allocate/free the memory of the extcon device. */ -struct extcon_dev *extcon_dev_allocate(const unsigned int *cable); -void extcon_dev_free(struct extcon_dev *edev); struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, const unsigned int *cable); void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); @@ -78,13 +76,6 @@ static inline int devm_extcon_dev_register(struct device= *dev, static inline void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev) { } =20 -static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *c= able) -{ - return ERR_PTR(-ENOSYS); -} - -static inline void extcon_dev_free(struct extcon_dev *edev) { } - static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *d= ev, const unsigned int *cable) { --=20 2.40.0.1.gaa8946217a0b From nobody Wed Feb 11 06:53:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BFACC7619A for ; Wed, 5 Apr 2023 15:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237448AbjDEP2h (ORCPT ); Wed, 5 Apr 2023 11:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238019AbjDEP2c (ORCPT ); Wed, 5 Apr 2023 11:28:32 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68A64E62 for ; Wed, 5 Apr 2023 08:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680708500; x=1712244500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1G96BxpRnc7nFZ7uPknxCBPGY6qbj+oRYDf0BwBN1Ek=; b=bZbix5R0d6bLfZE149yERlr+2vVlgZpjfevJw2yqrvoZcu9/DGWlCso+ W4/cV3RTd8e+44fFtDHSOOLGHrEMQdzBpkF+4cz+Dho+kJ6sfaA6jSqLr ZUBKGdY6PYF4WCHNlZSpLU3j5kUyYJE1AOySnAdSJ0+yXxNGUFyj6UEDf wLqThboEaHg4rzEOMZV9PXMSFEfOujpxZ/cmsEcL99kQ4WS7HCmwMBbD6 PQB+sYKahOhe7SH+hphCrGtiS2PKcxXY7oQwVkARP4DK25aiYeKs35lOg WfeN2DGgZFGT65XzgG8HuYgvruSUMMwnRlSgQZRxoP4D8RLcRC7kvHXtT Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="345064764" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="345064764" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:27:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="756028428" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="756028428" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Apr 2023 08:27:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A7D651D7; Wed, 5 Apr 2023 18:27:52 +0300 (EEST) From: Andy Shevchenko To: Chanwoo Choi , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham Subject: [PATCH v2 2/5] extcon: Get rid of not really used name field in struct extcon_dev Date: Wed, 5 Apr 2023 18:27:42 +0300 Message-Id: <20230405152745.24959-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> References: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The name field is always set to the parent device name and never altered. No need to keep it inside the struct extcon_dev as we always may derive it from the dev_name(edev->dev.parent) call. Moreover, the parent device pointer won't ever be NULL, otherwise we may not allocate the extcon device at all. Signed-off-by: Andy Shevchenko --- drivers/extcon/extcon.c | 12 +++--------- drivers/extcon/extcon.h | 3 --- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 47819c5144d5..75a0147703c0 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -387,7 +387,7 @@ static ssize_t name_show(struct device *dev, struct dev= ice_attribute *attr, { struct extcon_dev *edev =3D dev_get_drvdata(dev); =20 - return sysfs_emit(buf, "%s\n", edev->name); + return sysfs_emit(buf, "%s\n", dev_name(edev->dev.parent)); } static DEVICE_ATTR_RO(name); =20 @@ -885,7 +885,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *ex= tcon_name) =20 mutex_lock(&extcon_dev_list_lock); list_for_each_entry(sd, &extcon_dev_list, entry) { - if (!strcmp(sd->name, extcon_name)) + if (device_match_name(sd->dev.parent, extcon_name)) goto out; } sd =3D ERR_PTR(-EPROBE_DEFER); @@ -1269,12 +1269,6 @@ int extcon_dev_register(struct extcon_dev *edev) edev->dev.class =3D extcon_class; edev->dev.release =3D extcon_dev_release; =20 - edev->name =3D dev_name(edev->dev.parent); - if (IS_ERR_OR_NULL(edev->name)) { - dev_err(&edev->dev, - "extcon device name is null\n"); - return -EINVAL; - } dev_set_name(&edev->dev, "extcon%lu", (unsigned long)atomic_inc_return(&edev_no)); =20 @@ -1465,7 +1459,7 @@ EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); */ const char *extcon_get_edev_name(struct extcon_dev *edev) { - return !edev ? NULL : edev->name; + return edev ? dev_name(edev->dev.parent) : NULL; } EXPORT_SYMBOL_GPL(extcon_get_edev_name); =20 diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h index 49e4ed9f6450..9ce7042606d7 100644 --- a/drivers/extcon/extcon.h +++ b/drivers/extcon/extcon.h @@ -6,8 +6,6 @@ =20 /** * struct extcon_dev - An extcon device represents one external connector. - * @name: The name of this extcon device. Parent device name is - * used if NULL. * @supported_cable: Array of supported cable names ending with EXTCON_NON= E. * If supported_cable is NULL, cable name related APIs * are disabled. @@ -40,7 +38,6 @@ */ struct extcon_dev { /* Optional user initializing data */ - const char *name; const unsigned int *supported_cable; const u32 *mutually_exclusive; =20 --=20 2.40.0.1.gaa8946217a0b From nobody Wed Feb 11 06:53:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47D2EC7619A for ; Wed, 5 Apr 2023 15:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238675AbjDEP2k (ORCPT ); Wed, 5 Apr 2023 11:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238432AbjDEP2d (ORCPT ); Wed, 5 Apr 2023 11:28:33 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529F9198A for ; Wed, 5 Apr 2023 08:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680708512; x=1712244512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mokMk0IKOxShItonDjkrLXw1m8ClqXJpU5y5fyGrFXM=; b=J/6l7q14SAkYgST0FXd8NbFjZLitRVkbAirp8XaEIUHN3C7214V9Sd/f 4r64lRUjLFor9Wn+NjZUNhOURW+D6ODXzWZAULP04FavZ2jTYjKVptyhK dEN0iCLKfIfGLcwaPsYqD7CzrRpqNX28dPW8eryTa0O3MAikkPmJtk/Uk RkhHCK6yw3x14PY61sdyjtY2vw2gZNK4Yk6l7rJ83HsnVrp5PTTQt2YEG RFd6vZ7kimGjptNzXtWbqcHjaxxdkOkxLJC+r6LS1k3p2HckQEOcav4Ty XZJLB0+lNwPHdUwtEGwa/sEPnrRihwGvudFikk4fB0C9htjNRsVGK33H2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="345064766" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="345064766" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:27:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="756028425" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="756028425" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Apr 2023 08:27:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B2415443; Wed, 5 Apr 2023 18:27:52 +0300 (EEST) From: Andy Shevchenko To: Chanwoo Choi , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham , Bumwoo Lee Subject: [PATCH v2 3/5] extcon: Use unique number for the extcon device ID Date: Wed, 5 Apr 2023 18:27:43 +0300 Message-Id: <20230405152745.24959-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> References: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The use of atomic variable is still racy when we do not control which device has been unregistered and there is a (theoretical) possibility of the overflow that may cause a duplicate extcon device ID number to be allocated next time a device is registered. Replace above mentioned approach by using IDA framework. Signed-off-by: Andy Shevchenko Acked-by: Bumwoo Lee --- drivers/extcon/extcon.c | 15 ++++++++++++--- drivers/extcon/extcon.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 75a0147703c0..daaded92cf80 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -16,6 +16,7 @@ =20 #include #include +#include #include #include #include @@ -238,6 +239,7 @@ struct extcon_cable { =20 static struct class *extcon_class; =20 +static DEFINE_IDA(extcon_dev_ids); static LIST_HEAD(extcon_dev_list); static DEFINE_MUTEX(extcon_dev_list_lock); =20 @@ -1248,7 +1250,6 @@ static int extcon_alloc_groups(struct extcon_dev *ede= v) int extcon_dev_register(struct extcon_dev *edev) { int ret, index =3D 0; - static atomic_t edev_no =3D ATOMIC_INIT(-1); =20 ret =3D create_extcon_class(); if (ret < 0) @@ -1269,8 +1270,13 @@ int extcon_dev_register(struct extcon_dev *edev) edev->dev.class =3D extcon_class; edev->dev.release =3D extcon_dev_release; =20 - dev_set_name(&edev->dev, "extcon%lu", - (unsigned long)atomic_inc_return(&edev_no)); + ret =3D ida_alloc(&extcon_dev_ids, GFP_KERNEL); + if (ret < 0) + return ret; + + edev->id =3D ret; + + dev_set_name(&edev->dev, "extcon%d", edev->id); =20 ret =3D extcon_alloc_cables(edev); if (ret < 0) @@ -1333,6 +1339,7 @@ int extcon_dev_register(struct extcon_dev *edev) if (edev->max_supported) kfree(edev->cables); err_alloc_cables: + ida_free(&extcon_dev_ids, edev->id); =20 return ret; } @@ -1361,6 +1368,8 @@ void extcon_dev_unregister(struct extcon_dev *edev) return; } =20 + ida_free(&extcon_dev_ids, edev->id); + device_unregister(&edev->dev); =20 if (edev->mutually_exclusive && edev->max_supported) { diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h index 9ce7042606d7..5744c325e226 100644 --- a/drivers/extcon/extcon.h +++ b/drivers/extcon/extcon.h @@ -18,6 +18,7 @@ * {0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there * can be no simultaneous connections. * @dev: Device of this extcon. + * @id: Unique device ID of this extcon. * @state: Attach/detach state of this extcon. Do not provide at * register-time. * @nh_all: Notifier for the state change events for all supported @@ -43,6 +44,7 @@ struct extcon_dev { =20 /* Internal data. Please do not set. */ struct device dev; + unsigned int id; struct raw_notifier_head nh_all; struct raw_notifier_head *nh; struct list_head entry; --=20 2.40.0.1.gaa8946217a0b From nobody Wed Feb 11 06:53:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E57E9C761A6 for ; Wed, 5 Apr 2023 15:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238735AbjDEP2q (ORCPT ); Wed, 5 Apr 2023 11:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238179AbjDEP2e (ORCPT ); Wed, 5 Apr 2023 11:28:34 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B0B40DA for ; Wed, 5 Apr 2023 08:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680708512; x=1712244512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yHr3YfcH0isSmBGhveOFvMlA78zsK4oy4JPk9GZ0c+o=; b=kahV4+PdJT+XinlAM/aR4gsAUHl3SOgcGhanmK8/OvJoqHrHPyK1Wx2I 6Y8MEpTVuXsABRQlh8K+1glL9VkqYWx9vYG77u9XCztCJ8jUOZRV1DGGr 7DjWErKukjLpifco1EXuIrcXZTbwSsc/gqiFW5ditlkZlxAxUzkTHgJSS AHPOHM+1bJgesKyeyvZ8rfYYkuZR91CBI1Z4IFyue9mLr0hE8nQBgZS5q 9eJrSBCiA12+cwm5wrxnBNoFSPoAjpwZBK97OiV/5VFIjvKSwZtOLTH0N kuzOsLRIM6UOL311DICFVMC1zOkYz8umLDxvwrzp7NQqDAW1kVrSFvBE5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="345064768" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="345064768" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:27:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="756028427" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="756028427" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Apr 2023 08:27:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B9AF24F1; Wed, 5 Apr 2023 18:27:52 +0300 (EEST) From: Andy Shevchenko To: Chanwoo Choi , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham , Bumwoo Lee Subject: [PATCH v2 4/5] extcon: Use sizeof(*pointer) instead of sizeof(type) Date: Wed, 5 Apr 2023 18:27:44 +0300 Message-Id: <20230405152745.24959-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> References: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It is preferred to use sizeof(*pointer) instead of sizeof(type). The type of the variable can change and one needs not change the former (unlike the latter). No functional change intended. Signed-off-by: Andy Shevchenko Acked-by: Bumwoo Lee --- drivers/extcon/extcon.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index daaded92cf80..50c5fd454488 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1098,8 +1098,7 @@ static int extcon_alloc_cables(struct extcon_dev *ede= v) if (!edev->max_supported) return 0; =20 - edev->cables =3D kcalloc(edev->max_supported, - sizeof(struct extcon_cable), + edev->cables =3D kcalloc(edev->max_supported, sizeof(*edev->cables), GFP_KERNEL); if (!edev->cables) return -ENOMEM; @@ -1161,14 +1160,12 @@ static int extcon_alloc_muex(struct extcon_dev *ede= v) for (index =3D 0; edev->mutually_exclusive[index]; index++) ; =20 - edev->attrs_muex =3D kcalloc(index + 1, - sizeof(struct attribute *), + edev->attrs_muex =3D kcalloc(index + 1, sizeof(*edev->attrs_muex), GFP_KERNEL); if (!edev->attrs_muex) return -ENOMEM; =20 - edev->d_attrs_muex =3D kcalloc(index, - sizeof(struct device_attribute), + edev->d_attrs_muex =3D kcalloc(index, sizeof(*edev->d_attrs_muex), GFP_KERNEL); if (!edev->d_attrs_muex) { kfree(edev->attrs_muex); @@ -1214,8 +1211,8 @@ static int extcon_alloc_groups(struct extcon_dev *ede= v) return 0; =20 edev->extcon_dev_type.groups =3D kcalloc(edev->max_supported + 2, - sizeof(struct attribute_group *), - GFP_KERNEL); + sizeof(*edev->extcon_dev_type.groups), + GFP_KERNEL); if (!edev->extcon_dev_type.groups) return -ENOMEM; =20 @@ -1293,7 +1290,7 @@ int extcon_dev_register(struct extcon_dev *edev) spin_lock_init(&edev->lock); if (edev->max_supported) { edev->nh =3D kcalloc(edev->max_supported, sizeof(*edev->nh), - GFP_KERNEL); + GFP_KERNEL); if (!edev->nh) { ret =3D -ENOMEM; goto err_alloc_nh; --=20 2.40.0.1.gaa8946217a0b From nobody Wed Feb 11 06:53:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92586C76188 for ; Wed, 5 Apr 2023 15:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238721AbjDEP2n (ORCPT ); Wed, 5 Apr 2023 11:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237974AbjDEP2e (ORCPT ); Wed, 5 Apr 2023 11:28:34 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61083C3E for ; Wed, 5 Apr 2023 08:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680708512; x=1712244512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tQcZfnW0s5Te2GMdRZ+as8NovZGN837gxEAnvgXa0Ik=; b=K+TtFo7OJ1eW9qXqYOw+7/kYQa1qDWfK3FfZy05V/zu5niqUZUBz4Qfu FkkPU1Gxq8WFyzB+a/1Gh6A2f2jYNKma0uU+iF5OUDmVhkfjYIyUN0Y3p Vp7ZeBuSOXSVbMD7oiJKUm5W0buAJZnMM3TPkbYKu38N0SHfQvmac4eAO MAB7fidPHvNeFrTo3ZM2eHYAGQc95UbkQrrgzkynOpJUSRKFD27vFvg2A iAqLd5YDqWyYKcngrSBs63UvIFg7xmSIMVpfQFVhuGCOgoFgRheZTCC0t p7v3JzPP4DKpIG2Gxk5vHIwadxHGXtUWY+T/MsCZqkxsmGb9B824Aq28M w==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="345064784" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="345064784" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:27:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="756028446" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="756028446" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 05 Apr 2023 08:27:52 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C4D7F206; Wed, 5 Apr 2023 18:27:52 +0300 (EEST) From: Andy Shevchenko To: Chanwoo Choi , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham , Bumwoo Lee Subject: [PATCH v2 5/5] extcon: Drop unneeded assignments Date: Wed, 5 Apr 2023 18:27:45 +0300 Message-Id: <20230405152745.24959-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> References: <20230405152745.24959-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In one case the assignment is duplicative, in the other, it's better to move it into the loop =E2=80=94 the user of it. Signed-off-by: Andy Shevchenko Acked-by: Bumwoo Lee Acked-by: Chanwoo Choi again. --- drivers/extcon/extcon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 50c5fd454488..88ce0656d23c 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -245,7 +245,7 @@ static DEFINE_MUTEX(extcon_dev_list_lock); =20 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) { - int i =3D 0; + int i; =20 if (!edev->mutually_exclusive) return 0; @@ -1246,7 +1246,7 @@ static int extcon_alloc_groups(struct extcon_dev *ede= v) */ int extcon_dev_register(struct extcon_dev *edev) { - int ret, index =3D 0; + int ret, index; =20 ret =3D create_extcon_class(); if (ret < 0) @@ -1255,7 +1255,7 @@ int extcon_dev_register(struct extcon_dev *edev) if (!edev || !edev->supported_cable) return -EINVAL; =20 - for (; edev->supported_cable[index] !=3D EXTCON_NONE; index++); + for (index =3D 0; edev->supported_cable[index] !=3D EXTCON_NONE; index++); =20 edev->max_supported =3D index; if (index > SUPPORTED_CABLE_MAX) { --=20 2.40.0.1.gaa8946217a0b