Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp654263pxb; Wed, 20 Jan 2021 17:26:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQS03qlJA04rFsx7zxCM1U1iFnvqQ2YjljWxCzGEX3VFP6xKE9optDr8jcpr2se/IGfrUk X-Received: by 2002:a05:6402:424a:: with SMTP id g10mr9093044edb.236.1611192364501; Wed, 20 Jan 2021 17:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611192364; cv=none; d=google.com; s=arc-20160816; b=NzBlck5LVbpn1BxYs5VssqStf1gH3ebte4H5dgSy44QUrR1Zcrej/SvrgSU/qGYIXj NjgOOwN+RNSHrRnQsUjEpsOg8TEYhjUhOpZQthG25zx2GisDji59sfnSNKohBWmiamnD 32bWqQq40YBdG82HCvgXlX95BnzVUm/Amx+WDyGHzL4ZuHsI4EJRSFqoQkl83jeloDDW YFsQSTCJjjN1LQro8I31cUy7ZWM5sr9DnxL8xGJmmU1yBeNkIzyVQYzjKSBi8ViqHY4o E+Yi2Rk53gsYUFDYQ7hb83qP7VMaESKRv6ON7k4PD2rUuMMNbt4mkGrhP7Yod2fNQQGJ /juA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Qkj5MTn4PqAHlxRkP6Nm9pU0Bj533hacC35Vuu/cJN4=; b=Em4oeu1Cn9HvTKjKUSGTaUKqpNNGOt3UWkxiJW1pq1/7wKkfMf5/ia6a1UfdV+a79K JfZVVwCP2EJv4WnACMjypbMIENJthGuBBbo9D6xxj97ROa9tWoOqpTAZc5Z0RTgBu3DR hR4sNITN6lGJPZsEqHscMcgh84FUsnYLSFWU8TKSW3OqzK9nHMu5tKB7P95ZNpgm6G2f zgkHFU9LWE1MnrXjmflX/zO7RA0xM3/QW57F8HgoeJKGI0YXdgz6F/BHdeKPbEzIqiaV q6+0omQyt7/8KVNWjHBE3ODuO6F8tuBvuVceFUqaEP5KmFh5eaoe5owtugT9CO+8J+mZ R4sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BNnh+kRu; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si1221916ejv.374.2021.01.20.17.25.40; Wed, 20 Jan 2021 17:26:04 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BNnh+kRu; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731925AbhATV7W (ORCPT + 99 others); Wed, 20 Jan 2021 16:59:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53363 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388956AbhATVzB (ORCPT ); Wed, 20 Jan 2021 16:55:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611179615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qkj5MTn4PqAHlxRkP6Nm9pU0Bj533hacC35Vuu/cJN4=; b=BNnh+kRuLhHwo+qV+Dg08h346hWm8UeR6pHb3z6YWptboVwiZLUuYJutc7wLSUhyRUy8+6 4OfGc9tnV4X1E5M1KIS9rVyxjiSWmxf1ljByhBt4hBCdXFlms8H2dQ/TZxLwclJglujv4l Po0N6iTmNrc0DMN9/WZ+1+mWj4Ytl8c= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-255-FThySIhmOPaQXBAe_-qfog-1; Wed, 20 Jan 2021 16:53:33 -0500 X-MC-Unique: FThySIhmOPaQXBAe_-qfog-1 Received: by mail-ed1-f70.google.com with SMTP id e25so43841edq.6 for ; Wed, 20 Jan 2021 13:53:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Qkj5MTn4PqAHlxRkP6Nm9pU0Bj533hacC35Vuu/cJN4=; b=HWIPuxuOxoWjL244mF63Mc4w0hpw+8qJnDVnpz2R8HimM8bLhUaNVv0PKGDaYXkLze ejqgFWqThDb5qhEihsPNzn8RBwP1lbiJYnBXhY6AQAXZHvjxDWsIgugPe2XxM5bcp3I5 dymvZX0iZGeHWqDi2G8zXmhP1hcAdY+aFCOpExddL2T3nrGL2FwY10vUDDQkQNJ37MP2 qPcnI01HqCPyOJ+wP1Vqa6nb2z0Kg0nXS8vWbtqqH6+ceuyjupglu1rKb4R7c9dcIlmR WWZM5nFkhEJzjSs6vJKujX/ecvyxg1/shaEK2HaRUxzZB9WLRJf1yY7aLTM05ADk1QnA qcVA== X-Gm-Message-State: AOAM531ttZXjyyBtPJBczkChyOvB1BKIEsPHNFnzmZ8jAKgwXXXm/KoF qV/3r0s+Uv+sim3hsV3bxRl/vsm8/EJY2AlyfzI0nsDKuRBitU80oDzJ953noQnfvwv/8AtB/T0 z7pC7bqwTW3w5hCKYXtyzjLSOTafAbZxnt35g5pUx5VkkA8VmS9JlUS3aILoOGsTR6RCyy8rD+X lD X-Received: by 2002:a17:907:96a2:: with SMTP id hd34mr7649441ejc.494.1611179611876; Wed, 20 Jan 2021 13:53:31 -0800 (PST) X-Received: by 2002:a17:907:96a2:: with SMTP id hd34mr7649432ejc.494.1611179611693; Wed, 20 Jan 2021 13:53:31 -0800 (PST) Received: from x1.localdomain (2001-1c00-0c1e-bf00-37a3-353b-be90-1238.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:37a3:353b:be90:1238]) by smtp.gmail.com with ESMTPSA id j18sm1410893ejv.18.2021.01.20.13.53.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jan 2021 13:53:30 -0800 (PST) Subject: Re: [PATCH] ACPI: scan: Rearrange code related to acpi_get_device_data() To: "Rafael J. Wysocki" , Linux ACPI Cc: LKML References: <3445520.6OZ3MRzmT7@kreacher> From: Hans de Goede Message-ID: Date: Wed, 20 Jan 2021 22:53:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <3445520.6OZ3MRzmT7@kreacher> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 1/18/21 8:25 PM, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > There are two callers of acpi_get_device_data(), acpi_bus_get_device() > and acpi_bus_get_acpi_device(), but only one of them takes the int > return value into account. Moreover, the latter knows that it passes > a valid return pointer to acpi_get_device_data() and it properly > clears that pointer upfront, so it doesn't need acpi_get_device_data() > to do that. > > For this reason, rearrange acpi_get_device_data() to return a strct > acpi_device pointer instead of an int and adapt its callers to that. > > While at it, rename acpi_get_device_data() to handle_to_device(), > because the old name does not really reflect the functionality > provided by that function. > > No intentional functional impact. > > Signed-off-by: Rafael J. Wysocki Nice cleanup, patch looks good to me: Reviewed-by: Hans de Goede Regards, Hans > --- > > On top of https://patchwork.kernel.org/project/linux-acpi/patch/20210115215752.389656-1-hdegoede@redhat.com/ > > --- > drivers/acpi/scan.c | 35 +++++++++++++++++------------------ > 1 file changed, 17 insertions(+), 18 deletions(-) > > Index: linux-pm/drivers/acpi/scan.c > =================================================================== > --- linux-pm.orig/drivers/acpi/scan.c > +++ linux-pm/drivers/acpi/scan.c > @@ -578,29 +578,31 @@ static void acpi_scan_drop_device(acpi_h > mutex_unlock(&acpi_device_del_lock); > } > > -static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device, > - void (*callback)(void *)) > +static struct acpi_device *handle_to_device(acpi_handle handle, > + void (*callback)(void *)) > { > + struct acpi_device *adev = NULL; > acpi_status status; > > - if (!device) > - return -EINVAL; > - > - *device = NULL; > - > status = acpi_get_data_full(handle, acpi_scan_drop_device, > - (void **)device, callback); > - if (ACPI_FAILURE(status) || !*device) { > - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", > - handle)); > - return -ENODEV; > + (void **)&adev, callback); > + if (ACPI_FAILURE(status) || !adev) { > + acpi_handle_debug(handle, "No context!\n"); > + return NULL; > } > - return 0; > + return adev; > } > > int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) > { > - return acpi_get_device_data(handle, device, NULL); > + if (!device) > + return -EINVAL; > + > + *device = handle_to_device(handle, NULL); > + if (!*device) > + return -ENODEV; > + > + return 0; > } > EXPORT_SYMBOL(acpi_bus_get_device); > > @@ -612,10 +614,7 @@ static void get_acpi_device(void *dev) > > struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle) > { > - struct acpi_device *adev = NULL; > - > - acpi_get_device_data(handle, &adev, get_acpi_device); > - return adev; > + return handle_to_device(handle, get_acpi_device); > } > > void acpi_bus_put_acpi_device(struct acpi_device *adev) > > >