Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6197414rwl; Wed, 22 Mar 2023 07:41:51 -0700 (PDT) X-Google-Smtp-Source: AK7set9zneuRMlP0cLmC/cIo/MYdQxgijI/gCNmKtz6jLCZVBZzwNUfFII9qqEn+U+PdaJ/mip+q X-Received: by 2002:a17:907:c28f:b0:92b:e1ff:be30 with SMTP id tk15-20020a170907c28f00b0092be1ffbe30mr7228226ejc.4.1679496110916; Wed, 22 Mar 2023 07:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679496110; cv=none; d=google.com; s=arc-20160816; b=TsyqALxFChQ0hfwl5HXaIf93x5TaZaNtp3WK2/rCN9NbBfYtO5dzMQU+zIXT/lGFiH Y3O1j9qRL+3epi3SqFYnBtI722wVzGBwrj0RtPKoudsalVUhBuAxLMebkS5sRC4IwM/e QVppddFwJCOUYA9O4Or5+OhDSf/sSdqGfNgmLO3dVkImGnO3QRXDTiUPoATnBcsVEh3i AETbDsPVwDQeUWy4sgcEbZdcFhNL82HeEsxt5WpzTqJekx0He5Ln9b5xIZZ7gbamXVBY vPrlRzKKoIxWqKTvpEgTCxImEAVldUfpK/pcQMrTQugpOTIc8Z3ZwCWL+ikJVwnwIQaU NTsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+R3v7bAg6fEFYkj85Mqjq1dH5D3g3MC7z13TrFJ5h9Q=; b=CWnrVPJzJW7k2X6ZvU26qpqHwneCduPBNbie/hMiHOxR8czifChwM6hi4/fcipNq6w wlIzpBD4kEp+y3qqGMe+Cq2Yt7g2bA/Lbgvkt8YEnqs2EjScYHgt22U6G1TggC/qPfYI 3WpKgTwW8YesIVJoELH6Aa/uOyPSJQYiM/zkL1Avfjg01rI7OGPPQnMfitRzle5gSk33 AC2Q6VuVhMZY9DmYlRI3S5IaNXZ5synwSPt2Nvowb524x48NEBAMi7/6lcW0ylEfO7ZA cRvw9bw6hWHXHnLD/JArJ5Ydyzlw26Tu0ycndL66sxD21nMzItYbZes0JjMcEMBvJPTE 6O+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="CIsnt/nm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa15-20020a170907b9cf00b0092d5457516asi14035407ejc.589.2023.03.22.07.41.27; Wed, 22 Mar 2023 07:41:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="CIsnt/nm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbjCVOjj (ORCPT + 99 others); Wed, 22 Mar 2023 10:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbjCVOjZ (ORCPT ); Wed, 22 Mar 2023 10:39:25 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C2F410AB for ; Wed, 22 Mar 2023 07:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679495964; x=1711031964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fDzjemeuLsru23paImIk8ffwUuduPpzCedRvBa6jMLo=; b=CIsnt/nm5+QJXCD9nc11q3cm7138lGOzoMnEbLnN22aZWxHTOan7ZDjs M0idP2ZoBF63gYNw6hln/xGZNcOLkny3vx2M+lB46sF60YAEFcIBYpSbn B4QE3TjJVCJ4wD0J8Hc/VVDA5lbo9qIatv1ESyKgSk5nv3Su+ryy72MMn VmDg71Km4tmsVsaXzXpf9NWR96zctRhQgeQogaE8oBFZugHz8mmeE8L5J JWCJP4s/Fr/hkMwJnRo0zZFySnB25cnA8W/kbeY5BRk/MHZBRk0cmm1GA beuxywqBbCW9ty9lRS7Q5bSmsDxjfAdx7GiX1h7XAjlhxE0yJ3/XUMMIr A==; X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="327609304" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="327609304" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 07:39:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="792579434" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="792579434" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 22 Mar 2023 07:39:22 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id CED2C3DD; Wed, 22 Mar 2023 16:40:06 +0200 (EET) From: Andy Shevchenko To: Bumwoo Lee , Andy Shevchenko , linux-kernel@vger.kernel.org Cc: MyungJoo Ham , Chanwoo Choi Subject: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray() Date: Wed, 22 Mar 2023 16:39:59 +0200 Message-Id: <20230322144005.40368-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230322144005.40368-1-andriy.shevchenko@linux.intel.com> References: <20230322144005.40368-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since we have a generic helper, switch the module to use it. No functional change intended. Signed-off-by: Andy Shevchenko --- drivers/extcon/extcon.c | 25 +++++++++++-------------- drivers/extcon/extcon.h | 1 + 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 0d261ec6c473..a63e7eef02fd 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "extcon.h" @@ -1104,19 +1105,17 @@ static int extcon_alloc_cables(struct extcon_dev *edev) if (!edev->cables) return -ENOMEM; + edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported); + if (!edev->cable_names) { + kfree(edev->cables); + return -ENOMEM; + } + for (index = 0; index < edev->max_supported; index++) { cable = &edev->cables[index]; - str = kasprintf(GFP_KERNEL, "cable.%d", index); - if (!str) { - for (index--; index >= 0; index--) { - cable = &edev->cables[index]; - kfree(cable->attr_g.name); - } - - kfree(edev->cables); - return -ENOMEM; - } + str = edev->cable_names[index]; + strreplace(str, '-', '.'); cable->edev = edev; cable->cable_index = index; @@ -1341,8 +1340,7 @@ int extcon_dev_register(struct extcon_dev *edev) kfree(edev->attrs_muex); } err_alloc_muex: - for (index = 0; index < edev->max_supported; index++) - kfree(edev->cables[index].attr_g.name); + kfree_strarray(edev->cable_names, edev->max_supported); if (edev->max_supported) kfree(edev->cables); err_alloc_cables: @@ -1387,8 +1385,7 @@ void extcon_dev_unregister(struct extcon_dev *edev) kfree(edev->attrs_muex); } - for (index = 0; index < edev->max_supported; index++) - kfree(edev->cables[index].attr_g.name); + kfree_strarray(edev->cable_names, edev->max_supported); if (edev->max_supported) { kfree(edev->extcon_dev_type.groups); diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h index 877c0860e300..5624f65ba17a 100644 --- a/drivers/extcon/extcon.h +++ b/drivers/extcon/extcon.h @@ -58,6 +58,7 @@ struct extcon_dev { /* /sys/class/extcon/.../cable.n/... */ struct device_type extcon_dev_type; struct extcon_cable *cables; + char **cable_names; /* /sys/class/extcon/.../mutually_exclusive/... */ struct attribute_group attr_g_muex; -- 2.40.0.1.gaa8946217a0b