[3/7] drivers/extcon: add local variable for newly allocated attribute_group**

Message ID 20231009165741.746184-3-max.kellermann@ionos.com
State New
Headers
Series [1/7] drivers/rtc/sysfs: move code to count_attribute_groups() |

Commit Message

Max Kellermann Oct. 9, 2023, 4:57 p.m. UTC
  This allows the compiler to keep the pointer in a register and
prepares for making the struct field "const".

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 drivers/extcon/extcon.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
  

Comments

Greg KH Oct. 9, 2023, 5:28 p.m. UTC | #1
On Mon, Oct 09, 2023 at 06:57:36PM +0200, Max Kellermann wrote:
> This allows the compiler to keep the pointer in a register and
> prepares for making the struct field "const".

Again, registers have nothing to do with this.

thanks,

greg k-h
  

Patch

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 6f7a60d2ed91..e879690d4fef 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1202,6 +1202,7 @@  static int extcon_alloc_muex(struct extcon_dev *edev)
  */
 static int extcon_alloc_groups(struct extcon_dev *edev)
 {
+	const struct attribute_group **groups;
 	int index;
 
 	if (!edev)
@@ -1210,20 +1211,20 @@  static int extcon_alloc_groups(struct extcon_dev *edev)
 	if (!edev->max_supported)
 		return 0;
 
-	edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2,
-					  sizeof(*edev->extcon_dev_type.groups),
+	edev->extcon_dev_type.groups = groups = kcalloc(edev->max_supported + 2,
+					  sizeof(*groups),
 					  GFP_KERNEL);
-	if (!edev->extcon_dev_type.groups)
+	if (!groups)
 		return -ENOMEM;
 
 	edev->extcon_dev_type.name = dev_name(&edev->dev);
 	edev->extcon_dev_type.release = dummy_sysfs_dev_release;
 
 	for (index = 0; index < edev->max_supported; index++)
-		edev->extcon_dev_type.groups[index] = &edev->cables[index].attr_g;
+		groups[index] = &edev->cables[index].attr_g;
 
 	if (edev->mutually_exclusive)
-		edev->extcon_dev_type.groups[index] = &edev->attr_g_muex;
+		groups[index] = &edev->attr_g_muex;
 
 	edev->dev.type = &edev->extcon_dev_type;