From patchwork Sun Apr 4 18:14:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 72915 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1lT7Vy-00C1xA-OM; Sun, 04 Apr 2021 18:30:27 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230169AbhDDSa3 (ORCPT + 1 other); Sun, 4 Apr 2021 14:30:29 -0400 Received: from fgw23-7.mail.saunalahti.fi ([62.142.5.84]:18191 "EHLO fgw23-7.mail.saunalahti.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229861AbhDDSa2 (ORCPT ); Sun, 4 Apr 2021 14:30:28 -0400 X-Greylist: delayed 963 seconds by postgrey-1.27 at vger.kernel.org; Sun, 04 Apr 2021 14:30:28 EDT Received: from localhost (88-115-248-186.elisa-laajakaista.fi [88.115.248.186]) by fgw23.mail.saunalahti.fi (Halon) with ESMTP id 911d8938-9571-11eb-8ccd-005056bdfda7; Sun, 04 Apr 2021 21:14:16 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Daniel Scally , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yong Zhi , Sakari Ailus , Bingbu Cao , Tianshu Qiu , Mauro Carvalho Chehab Subject: [PATCH v1 1/1] media: ipu3-cio2: Fix referece counting when looping over ACPI devices Date: Sun, 4 Apr 2021 21:14:09 +0300 Message-Id: <20210404181409.1451026-1-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -1.4 (-) X-LSpam-Report: No, score=-1.4 required=5.0 tests=BAYES_00=-1.9,DKIM_ADSP_CUSTOM_MED=0.001,FORGED_GMAIL_RCVD=1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=no autolearn_force=no When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller. Fixes: 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver") Cc: Daniel Scally Cc: Sakari Ailus Signed-off-by: Andy Shevchenko Reviewed-by: Daniel Scally --- drivers/media/pci/intel/ipu3/cio2-bridge.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c index c2199042d3db..85f8b587405e 100644 --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c @@ -173,14 +173,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, int ret; for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) { - if (!adev->status.enabled) + if (!adev->status.enabled) { + acpi_dev_put(adev); continue; + } if (bridge->n_sensors >= CIO2_NUM_PORTS) { + acpi_dev_put(adev); dev_err(&cio2->dev, "Exceeded available CIO2 ports\n"); - cio2_bridge_unregister_sensors(bridge); - ret = -EINVAL; - goto err_out; + return -EINVAL; } sensor = &bridge->sensors[bridge->n_sensors]; @@ -228,7 +229,6 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, software_node_unregister_nodes(sensor->swnodes); err_put_adev: acpi_dev_put(sensor->adev); -err_out: return ret; }