Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5424218ybv; Tue, 11 Feb 2020 15:39:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxeOSAbn1K6OSAxBOv6eqy4c1f8TNoigSaTjzsYN4W73jZ74TEnyq2DstRCilkt62xYSZTI X-Received: by 2002:aca:5295:: with SMTP id g143mr4313523oib.25.1581464398575; Tue, 11 Feb 2020 15:39:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581464398; cv=none; d=google.com; s=arc-20160816; b=pu5GD83X6wCwrbIpdJYEa/jKfodt/vO/81I3s/nAU8FD0KSuyf2beAbNUR4JBfAEj6 nThI1D3DXwPQUe7e/PUv2EawuGs4st9i6ELOVZc91bYfUn7MR20KPyC0iy/aHUPL/NOc mP6BpaBEkmZNlJik2yMTuoC+xOXcNj1YGcVAVuKjkGKSlrdoCGMtPy7TSnGdO2hX10tI IBrdIHp9u65lr/yDtKP92TkKLAUDiUkhC2+UW8oMQRQ7f+8j0uaRgACPldZdgn2J7e9w 0yOH9ojDaX67YfeHNCzEOLSh2ATx65daBFbVy017vy/4m7EG5iutxhSA6bCx2wCbNB1O 2FWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DVQF/SZRSHi3hrAoJ8ff+W4fmeD4cJiM5tKy8e3r8PQ=; b=lPQKih9ktOnU1HfA+WFio3Fe7W7UKe/2jqKAT7YtLjp0PmxkqCy3tftu2vXQSKLaxx mvxSWrAJ7mhOFepIqtOH9YgOKTDg5KHdmtVo9WFkyCk97OOVQl5gT8d2w2w9CH3d7DEV +pUSI69qwsSzySehMZ1FeNK9dOklaMVhDJZnhyDorF5mO/g6LO48xD5IdWdDV8NPYDtu c3jAZjf7/lXwQdCf9jeKTWARhuT5cxyrsv5e9CKXu83vQ0QfZLAW8lPOhjwg1J7xridI SFdEO89cFvFPel3RQOZBGwf1ha6kejLFycBIu2gr2lR3srWW2TrEeA12eRdPrVm/4SB3 XQ0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si2673353otq.148.2020.02.11.15.39.46; Tue, 11 Feb 2020 15:39:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728250AbgBKXjD (ORCPT + 99 others); Tue, 11 Feb 2020 18:39:03 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:46840 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728189AbgBKXjA (ORCPT ); Tue, 11 Feb 2020 18:39:00 -0500 Received: from 79.184.254.199.ipv4.supernova.orange.pl (79.184.254.199) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.341) id 8117770a5ac94a1f; Wed, 12 Feb 2020 00:38:58 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Amit Kucheria Subject: [PATCH 07/28] PM: QoS: Clean up misc device file operations Date: Wed, 12 Feb 2020 00:00:12 +0100 Message-ID: <8377820.a6Hm6vfviC@kreacher> In-Reply-To: <1654227.8mz0SueHsU@kreacher> References: <1654227.8mz0SueHsU@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" Reorder the code to avoid using extra function header declarations for the pm_qos_power_*() family of functions and drop those declarations. Also clean up the internals of those functions to consolidate checks, avoid using redundant local variables and similar. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- kernel/power/qos.c | 62 +++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/kernel/power/qos.c b/kernel/power/qos.c index 57ff542a4f9d..9f67584d4466 100644 --- a/kernel/power/qos.c +++ b/kernel/power/qos.c @@ -83,21 +83,6 @@ static struct pm_qos_object *pm_qos_array[] = { &cpu_dma_pm_qos, }; -static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, - size_t count, loff_t *f_pos); -static ssize_t pm_qos_power_read(struct file *filp, char __user *buf, - size_t count, loff_t *f_pos); -static int pm_qos_power_open(struct inode *inode, struct file *filp); -static int pm_qos_power_release(struct inode *inode, struct file *filp); - -static const struct file_operations pm_qos_power_fops = { - .write = pm_qos_power_write, - .read = pm_qos_power_read, - .open = pm_qos_power_open, - .release = pm_qos_power_release, - .llseek = noop_llseek, -}; - /** * pm_qos_read_value - Return the current effective constraint value. * @c: List of PM QoS constraint requests. @@ -414,15 +399,6 @@ EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); /* User space interface to global PM QoS via misc device. */ -static int register_pm_qos_misc(struct pm_qos_object *qos) -{ - qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; - qos->pm_qos_power_miscdev.name = qos->name; - qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; - - return misc_register(&qos->pm_qos_power_miscdev); -} - static int pm_qos_power_open(struct inode *inode, struct file *filp) { struct pm_qos_request *req; @@ -439,9 +415,10 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp) static int pm_qos_power_release(struct inode *inode, struct file *filp) { - struct pm_qos_request *req; + struct pm_qos_request *req = filp->private_data; + + filp->private_data = NULL; - req = filp->private_data; pm_qos_remove_request(req); kfree(req); @@ -449,15 +426,13 @@ static int pm_qos_power_release(struct inode *inode, struct file *filp) } static ssize_t pm_qos_power_read(struct file *filp, char __user *buf, - size_t count, loff_t *f_pos) + size_t count, loff_t *f_pos) { - s32 value; - unsigned long flags; struct pm_qos_request *req = filp->private_data; + unsigned long flags; + s32 value; - if (!req) - return -EINVAL; - if (!pm_qos_request_active(req)) + if (!req || !pm_qos_request_active(req)) return -EINVAL; spin_lock_irqsave(&pm_qos_lock, flags); @@ -468,10 +443,9 @@ static ssize_t pm_qos_power_read(struct file *filp, char __user *buf, } static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, - size_t count, loff_t *f_pos) + size_t count, loff_t *f_pos) { s32 value; - struct pm_qos_request *req; if (count == sizeof(s32)) { if (copy_from_user(&value, buf, sizeof(s32))) @@ -484,12 +458,28 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, return ret; } - req = filp->private_data; - pm_qos_update_request(req, value); + pm_qos_update_request(filp->private_data, value); return count; } +static const struct file_operations pm_qos_power_fops = { + .write = pm_qos_power_write, + .read = pm_qos_power_read, + .open = pm_qos_power_open, + .release = pm_qos_power_release, + .llseek = noop_llseek, +}; + +static int register_pm_qos_misc(struct pm_qos_object *qos) +{ + qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; + qos->pm_qos_power_miscdev.name = qos->name; + qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; + + return misc_register(&qos->pm_qos_power_miscdev); +} + static int __init pm_qos_power_init(void) { int ret; -- 2.16.4