Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1646962pxy; Mon, 2 Aug 2021 07:02:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAav9jgMkNfmk2qBow05lfO2GVLQpZOOihq2B/6eurXfAB/VxqigNBvZeKHzgVzJC1Bl+t X-Received: by 2002:a02:11c6:: with SMTP id 189mr14994915jaf.20.1627912926281; Mon, 02 Aug 2021 07:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912926; cv=none; d=google.com; s=arc-20160816; b=OPWyiX7wzQ9DV8pJ7fg0mVW8toeMbkV7RZDGiQ+jfmyiBY+e6e+vcKGBunI3ny5itW URxB23nvYfxdHIX3WRJqk7CjnsdYsaH91T0LJArVfzKMriU27HuYvHICXW9mK4oMZm12 oz5f336H9K+sTxC1zTEtPrlcf7kSKFQ1eYV6os5MY35oBEN2ioWwMAEPEZ/k39Le5jpH f9MUavLBqlhncikdvdPsLDhfnqJuzjUQcSP4VKTxiV83zVCfAaRbBS8derowYBJn66PQ i8I5wNby1XqJovfxeC0z++0yZcZRVoNXtbg4bYbN4agS4YV2W/00ta3ozKu1eeUEGLiO R2YA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=egqTnwvXVL5ym92sHJrg5bfSug4lqZkszi9NgLYZCxE=; b=SygugRtt8KQSHFGlZ7FBSZjWj6OOTH2CvR/6R29KRyBpA2Pg6JKQFzDOaOeWemus/C GWTjTPA4K/DiVnbM9hXD4s6Hc4hESR81g2S3eIU1ELULsZ4lshbeKVgBg2SHydlT9CHW pvrPP8jtxLX0BDE1gieS6P5Bu1DJ2w2/4de/BgHVW9KFX4/aa3uaXGxAOJMJtfwC1JEN 0tzfjGN3m4q9pdhki8JCFhD8BQQN/SmMRQMpjdKZ60mg2aRTHPZOcin85ayKTh4fX1A5 kgVlBqNLbbTjGg8RFAE1aQTAycnPgLmTn3nWj5o8cDAiVv7HjcupbVpky45LEqlu8xpq wAmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gi2vWv1c; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si11970070jaf.48.2021.08.02.07.01.55; Mon, 02 Aug 2021 07:02:06 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gi2vWv1c; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236510AbhHBN7g (ORCPT + 99 others); Mon, 2 Aug 2021 09:59:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:33500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235756AbhHBNyV (ORCPT ); Mon, 2 Aug 2021 09:54:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6168E61158; Mon, 2 Aug 2021 13:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912360; bh=rhU+x3Q+q9wRUeuLNNUDEwueUlY9MyUsE1nn2CaTkp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gi2vWv1cs78/FcFtgbjVOlGiWUEn3y6MdSgHfjb4DDZq2zgMRG//HvO4BtHuXu71H GuM19TamW+91c37CwOibPUt6Qab3zp+W/FeOU0N/WkTyYu1cSfiDj0xNHCQhIB8HFR N3Cs5iE8bCvk95U6bF52Aor6dmwofkrfWtpaZw6g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Pandruvada , "Rafael J. Wysocki" Subject: [PATCH 5.10 07/67] ACPI: DPTF: Fix reading of attributes Date: Mon, 2 Aug 2021 15:44:30 +0200 Message-Id: <20210802134339.270939936@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134339.023067817@linuxfoundation.org> References: <20210802134339.023067817@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Pandruvada commit 41a8457f3f6f829be1f8f8fa7577a46b9b7223ef upstream. The current assumption that methods to read PCH FIVR attributes will return integer, is not correct. There is no good way to return integer as negative numbers are also valid. These read methods return a package of integers. The first integer returns status, which is 0 on success and any other value for failure. When the returned status is zero, then the second integer returns the actual value. This change fixes this issue by replacing acpi_evaluate_integer() with acpi_evaluate_object() and use acpi_extract_package() to extract results. Fixes: 2ce6324eadb01 ("ACPI: DPTF: Add PCH FIVR participant driver") Signed-off-by: Srinivas Pandruvada Cc: 5.10+ # 5.10+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/dptf/dptf_pch_fivr.c | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) --- a/drivers/acpi/dptf/dptf_pch_fivr.c +++ b/drivers/acpi/dptf/dptf_pch_fivr.c @@ -9,6 +9,42 @@ #include #include +struct pch_fivr_resp { + u64 status; + u64 result; +}; + +static int pch_fivr_read(acpi_handle handle, char *method, struct pch_fivr_resp *fivr_resp) +{ + struct acpi_buffer resp = { sizeof(struct pch_fivr_resp), fivr_resp}; + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer format = { sizeof("NN"), "NN" }; + union acpi_object *obj; + acpi_status status; + int ret = -EFAULT; + + status = acpi_evaluate_object(handle, method, NULL, &buffer); + if (ACPI_FAILURE(status)) + return ret; + + obj = buffer.pointer; + if (!obj || obj->type != ACPI_TYPE_PACKAGE) + goto release_buffer; + + status = acpi_extract_package(obj, &format, &resp); + if (ACPI_FAILURE(status)) + goto release_buffer; + + if (fivr_resp->status) + goto release_buffer; + + ret = 0; + +release_buffer: + kfree(buffer.pointer); + return ret; +} + /* * Presentation of attributes which are defined for INT1045 * They are: @@ -23,15 +59,14 @@ static ssize_t name##_show(struct device char *buf)\ {\ struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ - unsigned long long val;\ - acpi_status status;\ + struct pch_fivr_resp fivr_resp;\ + int status;\ +\ + status = pch_fivr_read(acpi_dev->handle, #method, &fivr_resp);\ + if (status)\ + return status;\ \ - status = acpi_evaluate_integer(acpi_dev->handle, #method,\ - NULL, &val);\ - if (ACPI_SUCCESS(status))\ - return sprintf(buf, "%d\n", (int)val);\ - else\ - return -EINVAL;\ + return sprintf(buf, "%llu\n", fivr_resp.result);\ } #define PCH_FIVR_STORE(name, method) \