From patchwork Fri Oct 6 16:43:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 149355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp461059vqo; Fri, 6 Oct 2023 09:47:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnRs5VRMQ/Qru+wHrOj5W8ziwmSCKA7AOb4Q+7bJ1fJQIkHTwuTeu7ii+jReEMcuydfDkX X-Received: by 2002:a05:6358:279c:b0:143:2f7e:aa with SMTP id l28-20020a056358279c00b001432f7e00aamr9258885rwb.28.1696610836138; Fri, 06 Oct 2023 09:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696610836; cv=none; d=google.com; s=arc-20160816; b=wvse8iDN8IY7V2ijWXsaBQnH78BH9cTAtELMBlMU7xgOGlT+YvgsmNOkm8fdUlhQc5 7DYdvaNUBm5Agro2M232isRhqKmFnOC4YotZC9hYvh4zlGD+VwAcivhmOJMZOzPofYNs y38zL369kd2+S9LOLREzfAiMz8F8M7wi/3sf7C/LloKN5hZHK7cfvOWL3pHAkhUn+kkD 7qabSVw5FOw0tVkI3ES326ImpEfMFhqpfCadO7CQewvsCNJ2MOIXAfseu8fPaVNZrQ/H 5xlCmmKDvtok+ParKEw6UDJyW7woSZZbAA3C6OBGE4/i10xD89C4n+P9gHWDMHVWeWGM B3tQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WtMlVgRzp70nH4S1U8lleZdewK/AG65HykbNxQNcnFI=; fh=lPbYBnLdGU3qVL6qxF7FHAh9gqN/mtoDwV1+tMFpAU4=; b=Qi+lLrfKsRkBqVmXf1ZJzd0qSS0WaQlAc4ty0jBENH53jVgHUpKtEy2L5Y9kQxlqbu hlCmDkDPtW7XXb29rh4u4vJRfVVQZBj4SmBUrRyOKWuC69hJKW9GP0vXUjivI045hE7X 8cV3MBtXSvxvSB8zsZncneKi7vrkJtmGPSCrQZ0dHszsrRAscWBf4e7vyJkkuZa7axgA syqM4/wqx1k3jjX6VrZ/a0JOWOkGVZJgPqRxx2UdQ5EDxxEdKpTa60Xdy8neq9uHAv7W XKxQrrKeUszjw6K6noD2KpAx/d6Fi3zoV7gAq3S7O+dsgGIabQRAWJYs63h+fFLPRssO e4xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GOqUp5cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id be3-20020a656e43000000b0058555ea0a21si4041499pgb.571.2023.10.06.09.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 09:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GOqUp5cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 069198027884; Fri, 6 Oct 2023 09:46:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbjJFQqF (ORCPT + 18 others); Fri, 6 Oct 2023 12:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232947AbjJFQqD (ORCPT ); Fri, 6 Oct 2023 12:46:03 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 614DDD58; Fri, 6 Oct 2023 09:44: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=1696610676; x=1728146676; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=q/fbl8MRoHNlScwMG1/DLFJFN//gIakiG3syYUF579U=; b=GOqUp5cKYLZMRlzVJqRWnytlUT7XPLcrt5niy0SJhEe6H4C/KnDPZgcr ER/S1xErSYVb5BM/UKqaSjDTirZlxpa+nHdi1JvskQorMS9rJlmp7y7mp KmtpfgMfszxGd/KoWGoaTqRyxMarM9IUfz6wkxKTUveLZSg0F8zar8GfG jMTZ/rDkfGuNrxyikSCUgr6wO4O0P4ULx7chfn0j6WafwcLa6U8XEb8zH M3UT/iEG2bECV9l1ldfoh4DvkU1vxYUyJoSLcrwKgHrrsQJG6vT1Lf2gf h1xTCi3oWDQtFDb9QbaiEHseM2bU4uoYwMBsG//kayyZ0tih5NPjctu5J w==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="383672548" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="383672548" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 09:43:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="787448487" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="787448487" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 06 Oct 2023 09:43:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4506C430; Fri, 6 Oct 2023 19:43:14 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Valentina Manea , Shuah Khan , Hongren Zheng , Greg Kroah-Hartman Subject: [PATCH v2 1/1] usbip: Use platform_device_register_full() Date: Fri, 6 Oct 2023 19:43:12 +0300 Message-Id: <20231006164312.3528524-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 06 Oct 2023 09:46:19 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779025404380310690 X-GMAIL-MSGID: 1779025404380310690 The code to create the child platform device is essentially the same as what platform_device_register_full() does, so change over to use that same function to reduce duplication. Signed-off-by: Andy Shevchenko Acked-by: Shuah Khan --- v2: (hopefully) fixed run-time NULL-dereference (LKP) drivers/usb/usbip/vhci_hcd.c | 55 +++++++++++++----------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 37d1fc34e8a5..f845b91848b9 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -1139,7 +1139,8 @@ static int hcd_name_to_id(const char *name) static int vhci_setup(struct usb_hcd *hcd) { - struct vhci *vhci = *((void **)dev_get_platdata(hcd->self.controller)); + struct vhci *vhci = dev_get_platdata(hcd->self.controller); + if (usb_hcd_is_primary_hcd(hcd)) { vhci->vhci_hcd_hs = hcd_to_vhci_hcd(hcd); vhci->vhci_hcd_hs->vhci = vhci; @@ -1256,7 +1257,7 @@ static int vhci_get_frame_number(struct usb_hcd *hcd) /* FIXME: suspend/resume */ static int vhci_bus_suspend(struct usb_hcd *hcd) { - struct vhci *vhci = *((void **)dev_get_platdata(hcd->self.controller)); + struct vhci *vhci = dev_get_platdata(hcd->self.controller); unsigned long flags; dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); @@ -1270,7 +1271,7 @@ static int vhci_bus_suspend(struct usb_hcd *hcd) static int vhci_bus_resume(struct usb_hcd *hcd) { - struct vhci *vhci = *((void **)dev_get_platdata(hcd->self.controller)); + struct vhci *vhci = dev_get_platdata(hcd->self.controller); int rc = 0; unsigned long flags; @@ -1337,7 +1338,7 @@ static const struct hc_driver vhci_hc_driver = { static int vhci_hcd_probe(struct platform_device *pdev) { - struct vhci *vhci = *((void **)dev_get_platdata(&pdev->dev)); + struct vhci *vhci = dev_get_platdata(&pdev->dev); struct usb_hcd *hcd_hs; struct usb_hcd *hcd_ss; int ret; @@ -1395,7 +1396,7 @@ static int vhci_hcd_probe(struct platform_device *pdev) static void vhci_hcd_remove(struct platform_device *pdev) { - struct vhci *vhci = *((void **)dev_get_platdata(&pdev->dev)); + struct vhci *vhci = dev_get_platdata(&pdev->dev); /* * Disconnects the root hub, @@ -1430,7 +1431,7 @@ static int vhci_hcd_suspend(struct platform_device *pdev, pm_message_t state) if (!hcd) return 0; - vhci = *((void **)dev_get_platdata(hcd->self.controller)); + vhci = dev_get_platdata(hcd->self.controller); spin_lock_irqsave(&vhci->lock, flags); @@ -1493,13 +1494,10 @@ static struct platform_driver vhci_driver = { static void del_platform_devices(void) { - struct platform_device *pdev; int i; for (i = 0; i < vhci_num_controllers; i++) { - pdev = vhcis[i].pdev; - if (pdev != NULL) - platform_device_unregister(pdev); + platform_device_unregister(vhcis[i].pdev); vhcis[i].pdev = NULL; } sysfs_remove_link(&platform_bus.kobj, driver_name); @@ -1519,45 +1517,32 @@ static int __init vhci_hcd_init(void) if (vhcis == NULL) return -ENOMEM; - for (i = 0; i < vhci_num_controllers; i++) { - vhcis[i].pdev = platform_device_alloc(driver_name, i); - if (!vhcis[i].pdev) { - i--; - while (i >= 0) - platform_device_put(vhcis[i--].pdev); - ret = -ENOMEM; - goto err_device_alloc; - } - } - for (i = 0; i < vhci_num_controllers; i++) { - void *vhci = &vhcis[i]; - ret = platform_device_add_data(vhcis[i].pdev, &vhci, sizeof(void *)); - if (ret) - goto err_driver_register; - } - ret = platform_driver_register(&vhci_driver); if (ret) goto err_driver_register; for (i = 0; i < vhci_num_controllers; i++) { - ret = platform_device_add(vhcis[i].pdev); + struct platform_device_info pdevinfo = { + .name = driver_name, + .id = i, + .data = &vhcis[i], + .size_data = sizeof(void *), + }; + + vhcis[i].pdev = platform_device_register_full(&pdevinfo); + ret = PTR_ERR_OR_ZERO(vhcis[i].pdev); if (ret < 0) { - i--; - while (i >= 0) - platform_device_del(vhcis[i--].pdev); + while (i--) + platform_device_unregister(vhcis[i].pdev); goto err_add_hcd; } } - return ret; + return 0; err_add_hcd: platform_driver_unregister(&vhci_driver); err_driver_register: - for (i = 0; i < vhci_num_controllers; i++) - platform_device_put(vhcis[i].pdev); -err_device_alloc: kfree(vhcis); return ret; }