Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1368912pxj; Fri, 21 May 2021 12:27:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9V2gyuitUXrp5MhX/DxElEztIROBo2Ms+nEAPyRA7TgU8vq4bxB6QNBRrqTyS7UiA+fVR X-Received: by 2002:a17:906:e98:: with SMTP id p24mr11717750ejf.478.1621625236220; Fri, 21 May 2021 12:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621625236; cv=none; d=google.com; s=arc-20160816; b=jPXeKQVjmhSIukG++chrGqkkI1L4fI+tWiEsri/UdLW1H0n2VDUxw6MRpU7Yz1HBjG m1uw3lHLZGIVEsxZCmgEtS9HumW+bEd2RBI/0zoPvaY3FWr1+fesYos3iYS4kNg8t5Q5 jvb5f783+jqwQ4pzu6n8DK1dnPxICJWo6r0iGjCGZbrul81NdPxkM+Ini7EvJqJXlPmp llLIMDdubzT5Hm3oUL4HiU4bS4vhGTbqiA6QZeGCnBDOYf/dBByW1Rr7xyHIuXspwXKV QGIeu5Ma3uCraw2AcWnmxdcP3iU4JYBZ6c2z7lo3QaAbrVZhi828npszyl9j6RY/2q/b oX+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=K1iin/fsWDM3w5QyDMVs0rUZIL7VQZLTGcYt+0lEbCQ=; b=GWT1QLQ5T4DdbLFBFUfNoduI9tR/i56kaAvk7zPghCHrniVQZogMCzPa6B6pbRXGaU YliIljxy5vWJfUaYt3AyXpYtF6ketNinOGB9cFDoVujT0RP648U2TGwmyEJBk+eKXcr5 7lelmeIuzVR6xzcyTnHCayh5YwXG6c1fE3b0d9EostFEzhB9K5NTqiVbh730YpzdhDlc pdIepkl+BoxUmthb2upNXsttzn002aCCZ9Eolsq8cc1iJzx2u3x3PBC00moEPylJRABu vxTXIyveBwNeg4JTqFVxibOy0b9wuzgRf/l3Lg6HdPKvlSdVBiyiuwHeG5l0BY+72l5t i0jA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si6234831ejq.186.2021.05.21.12.26.53; Fri, 21 May 2021 12:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236642AbhETTmZ (ORCPT + 99 others); Thu, 20 May 2021 15:42:25 -0400 Received: from mail-oi1-f170.google.com ([209.85.167.170]:46002 "EHLO mail-oi1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232281AbhETTmY (ORCPT ); Thu, 20 May 2021 15:42:24 -0400 Received: by mail-oi1-f170.google.com with SMTP id w127so13653384oig.12; Thu, 20 May 2021 12:41:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K1iin/fsWDM3w5QyDMVs0rUZIL7VQZLTGcYt+0lEbCQ=; b=EEk4riasDquK6JGMs0d9+/LhG8hgfs3pNF++ijDNiIWI48jWXFM5wIsWlRCrB/6P3W 6JIoHYfoPSOre9dCce/anfyahEM/G9GK+JeM+pIm/9jA5wXF2Y/xIIgKhnzzEVPoPhmr 2Hjw125qoA6+bwhrdo1p25VwYSUvc5kLdJy4ruoZg0LzQT5m/LhXyUtREwp8Qjz6ltn1 IwJxf5t8scJGdrgWZzrY97Di2LP58pgF42YR9/op8n6pwwGvrC2qYb+0ssTVbL2GEFuk HW4ulv/hzgfrvcrnTy4gjrmRtO6B9jgYOCM3Y2UrtcE8C0z9UOuzIjcNxCzInFQyudAG kRvA== X-Gm-Message-State: AOAM530XUUSfwwB+BdMJxzxdJ6/I+/Ycnie8MUbG/nTdmUjMxr1nHX3z WwXFf/r71oELY6pbuRr35fyAlFql4u34lDvs6QQ= X-Received: by 2002:aca:380a:: with SMTP id f10mr4623632oia.157.1621539661194; Thu, 20 May 2021 12:41:01 -0700 (PDT) MIME-Version: 1.0 References: <20210519210253.3578025-1-andy.shevchenko@gmail.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 20 May 2021 21:40:50 +0200 Message-ID: Subject: Re: [PATCH v1 1/1] ACPI: utils: Fix reference counting in for_each_acpi_dev_match() To: Andy Shevchenko Cc: "Rafael J. Wysocki" , Daniel Scally , ACPI Devel Maling List , Linux Kernel Mailing List , Linux Media Mailing List , "open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" , "Rafael J. Wysocki" , Len Brown , Yong Zhi , Sakari Ailus , Bingbu Cao , Tianshu Qiu , Mauro Carvalho Chehab , Robert Moore , Erik Kaneda Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 20, 2021 at 9:13 PM Rafael J. Wysocki wrote: > > On Wed, May 19, 2021 at 11:19 PM Andy Shevchenko > wrote: > > > > Currently it's possible to iterate over the dangling pointer in case the device > > suddenly disappears. This may happen becase callers put it at the end of a loop. > > > > Instead, let's move that call inside acpi_dev_get_next_match_dev(). > > Not really. OK, I see what you want to achieve and the macro is actually buggy, because it leaves unbalanced references behind. > > Fixes: 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver") > > Fixes: bf263f64e804 ("media: ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro") > > Cc: Daniel Scally > > Cc: Sakari Ailus > > Signed-off-by: Andy Shevchenko > > --- > > drivers/acpi/utils.c | 5 +---- > > drivers/media/pci/intel/ipu3/cio2-bridge.c | 8 +++----- > > include/acpi/acpi_bus.h | 5 ----- > > 3 files changed, 4 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > > index 3b54b8fd7396..ccfc484dbffd 100644 > > --- a/drivers/acpi/utils.c > > +++ b/drivers/acpi/utils.c > > @@ -846,10 +846,6 @@ EXPORT_SYMBOL(acpi_dev_present); > > * Return the next match of ACPI device if another matching device was present > > * at the moment of invocation, or NULL otherwise. > > * > > - * FIXME: The function does not tolerate the sudden disappearance of @adev, e.g. > > - * in the case of a hotplug event. That said, the caller should ensure that > > - * this will never happen. > > - * > > * The caller is responsible for invoking acpi_dev_put() on the returned device. > > * > > * See additional information in acpi_dev_present() as well. But the kerneldoc really needs to say that the caller is required to obtain a reference on adev before passing it here, because that reference will be dropped and the object pointed to by adev may not be present any more after this returns. > > @@ -866,6 +862,7 @@ acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const cha > > match.hrv = hrv; > > > > dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb); > > + acpi_dev_put(adev);