public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count
@ 2023-01-02 20:29 Andy Shevchenko
  2023-01-02 20:29 ` [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe Andy Shevchenko
  2023-01-03  9:28 ` [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Heikki Krogerus
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2023-01-02 20:29 UTC (permalink / raw)
  To: Heikki Krogerus, linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Andy Shevchenko

When acpi_dev_get_memory_resources() fails, the reference count is
left bumped. Drop it as it's done in the other error paths.

Fixes: 43d596e32276 ("usb: typec: intel_pmc_mux: Check the port status before connect")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index fdbf3694e21f..87e2c9130607 100644
--- a/drivers/usb/typec/mux/intel_pmc_mux.c
+++ b/drivers/usb/typec/mux/intel_pmc_mux.c
@@ -614,8 +614,10 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
-	if (ret < 0)
+	if (ret < 0) {
+		acpi_dev_put(adev);
 		return ret;
+	}
 
 	rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
 	if (rentry)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe
  2023-01-02 20:29 [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Andy Shevchenko
@ 2023-01-02 20:29 ` Andy Shevchenko
  2023-01-03  9:29   ` Heikki Krogerus
  2023-01-03  9:28 ` [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Heikki Krogerus
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2023-01-02 20:29 UTC (permalink / raw)
  To: Heikki Krogerus, linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Andy Shevchenko

There is no need to call acpi_dev_present() followed by
acpi_dev_get_first_match_dev() as they both do the same
with only difference in the returning value. Instead,
call the latter and check its result.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index 87e2c9130607..34e4188a40ff 100644
--- a/drivers/usb/typec/mux/intel_pmc_mux.c
+++ b/drivers/usb/typec/mux/intel_pmc_mux.c
@@ -602,16 +602,15 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
 	int ret;
 
 	for (dev_id = &iom_acpi_ids[0]; dev_id->id[0]; dev_id++) {
-		if (acpi_dev_present(dev_id->id, NULL, -1)) {
-			pmc->iom_port_status_offset = (u32)dev_id->driver_data;
-			adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
+		if (adev)
 			break;
-		}
 	}
-
 	if (!adev)
 		return -ENODEV;
 
+	pmc->iom_port_status_offset = (u32)dev_id->driver_data;
+
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_memory_resources(adev, &resource_list);
 	if (ret < 0) {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count
  2023-01-02 20:29 [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Andy Shevchenko
  2023-01-02 20:29 ` [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe Andy Shevchenko
@ 2023-01-03  9:28 ` Heikki Krogerus
  1 sibling, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2023-01-03  9:28 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-usb, linux-kernel, Greg Kroah-Hartman

On Mon, Jan 02, 2023 at 10:29:32PM +0200, Andy Shevchenko wrote:
> When acpi_dev_get_memory_resources() fails, the reference count is
> left bumped. Drop it as it's done in the other error paths.
> 
> Fixes: 43d596e32276 ("usb: typec: intel_pmc_mux: Check the port status before connect")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/mux/intel_pmc_mux.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
> index fdbf3694e21f..87e2c9130607 100644
> --- a/drivers/usb/typec/mux/intel_pmc_mux.c
> +++ b/drivers/usb/typec/mux/intel_pmc_mux.c
> @@ -614,8 +614,10 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
>  
>  	INIT_LIST_HEAD(&resource_list);
>  	ret = acpi_dev_get_memory_resources(adev, &resource_list);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		acpi_dev_put(adev);
>  		return ret;
> +	}
>  
>  	rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
>  	if (rentry)
> -- 
> 2.35.1

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe
  2023-01-02 20:29 ` [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe Andy Shevchenko
@ 2023-01-03  9:29   ` Heikki Krogerus
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2023-01-03  9:29 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-usb, linux-kernel, Greg Kroah-Hartman

On Mon, Jan 02, 2023 at 10:29:33PM +0200, Andy Shevchenko wrote:
> There is no need to call acpi_dev_present() followed by
> acpi_dev_get_first_match_dev() as they both do the same
> with only difference in the returning value. Instead,
> call the latter and check its result.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/mux/intel_pmc_mux.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
> index 87e2c9130607..34e4188a40ff 100644
> --- a/drivers/usb/typec/mux/intel_pmc_mux.c
> +++ b/drivers/usb/typec/mux/intel_pmc_mux.c
> @@ -602,16 +602,15 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)
>  	int ret;
>  
>  	for (dev_id = &iom_acpi_ids[0]; dev_id->id[0]; dev_id++) {
> -		if (acpi_dev_present(dev_id->id, NULL, -1)) {
> -			pmc->iom_port_status_offset = (u32)dev_id->driver_data;
> -			adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
> +		adev = acpi_dev_get_first_match_dev(dev_id->id, NULL, -1);
> +		if (adev)
>  			break;
> -		}
>  	}
> -
>  	if (!adev)
>  		return -ENODEV;
>  
> +	pmc->iom_port_status_offset = (u32)dev_id->driver_data;
> +
>  	INIT_LIST_HEAD(&resource_list);
>  	ret = acpi_dev_get_memory_resources(adev, &resource_list);
>  	if (ret < 0) {
> -- 
> 2.35.1

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-03  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-02 20:29 [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Andy Shevchenko
2023-01-02 20:29 ` [PATCH v1 2/2] usb: typec: intel_pmc_mux: Deduplicate ACPI matching in probe Andy Shevchenko
2023-01-03  9:29   ` Heikki Krogerus
2023-01-03  9:28 ` [PATCH v1 1/2] usb: typec: intel_pmc_mux: Don't leak the ACPI device reference count Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox