From patchwork Sat Aug 18 13:24:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10569551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8EAF14E1 for ; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97D902A836 for ; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B8CE2A84D; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 139CE2A839 for ; Sat, 18 Aug 2018 13:25:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726302AbeHRQc2 (ORCPT ); Sat, 18 Aug 2018 12:32:28 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:42764 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbeHRQc1 (ORCPT ); Sat, 18 Aug 2018 12:32:27 -0400 Received: by mail-ed1-f67.google.com with SMTP id r4-v6so5962226edp.9 for ; Sat, 18 Aug 2018 06:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=FV0dNHdRcB4ZhsnEc2fPA731UxnGGox6WwKOreslgto=; b=cSWf8I5iIpCx97/UujKEH5f4Pm0C7XXGUtPWnFGZU9GSyRcVBp2qOKaGIboDU+Sl+w 5ECYG43t986TYdBu/urRth/3/g7/TSTesCmV5AWASVMFPs0tNgZuB3pS7wYbpTrXeoee nE2uxnbQSt4yhH3oxCefGIJk83OnLq+7Pa8Zw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FV0dNHdRcB4ZhsnEc2fPA731UxnGGox6WwKOreslgto=; b=bcbGc6rAC/USoBwvQeydaGw6Z8zRqhsQjfUgr7zVCdxtIvKAJ1AboWSBOlp6e7IMlw WmBnqgBf665p/+pGRwtlGDZHCbQtODxec0nHepAh+K04Y1Ch0wCzcNlvcjC9VMJ/VWTQ 4hxIkVwatnKnt/nhqjtYcTLIqx0/e/Q1d2pBM37lMcqZXjnzWgq5NtGstjO6ZXdDfw6M CQwyAdJ4Bsa8HaoxX9ZOHY1gqNlfOZt01y4by2Q9sW/W3HLSkgo45jrm498yQmMOZGwQ G71Cpxx8CAN3145pLW99V3P3Ya10GuxCHlNSJvqCpm+yTvzjyRX48KBykF/ybDtFO1OC KGOw== X-Gm-Message-State: AOUpUlH9BP/sXWt3tfV0+D2tkD3i3ahjnwUlu+fvpkdISau/+bN/s9YC wFqHtkZIdW8+rfNX1uBCVrOsTA== X-Google-Smtp-Source: AA+uWPw+UKhHcsh5t3gZC8ty9gStC7DIEPFZMt8/J29uy22Ne6sIfHjTNhfp3IGa4AJ3alXFKM/0QQ== X-Received: by 2002:aa7:c68b:: with SMTP id n11-v6mr47564358edq.122.1534598683408; Sat, 18 Aug 2018 06:24:43 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id a11-v6sm2739032edn.95.2018.08.18.06.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:24:42 -0700 (PDT) From: Rasmus Villemoes To: Jonathan Corbet , Alexander Viro Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , Andreas Dilger , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , linux-nfs@vger.kernel.org, cluster-devel@redhat.com, Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Thierry Reding , Lorenzo Pieralisi Subject: [PATCH v2 1/8] seq_file: introduce seq_open_data helper Date: Sat, 18 Aug 2018 15:24:27 +0200 Message-Id: <20180818132434.9515-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are quite a few callers of seq_open that could be simplified by setting the ->private member via the seq_open call instead of fetching file->private_data afterwards. Signed-off-by: Rasmus Villemoes Reviewed-by: Andy Shevchenko --- v2: - Fix some copy-pastos spotted by Andreas. - Ensure everybody hit by an example patch also gets this cover letter/introducing patch. - Include a few fs/ examples. I've just included a few examples of possible users of this helper, there are many more similar cases. As a bonus, 7/8 fix a potential NULL deref (if one believes that seq_open can actually fail). seq_open_private would have been a better name, but that one is already taken... Documentation/filesystems/seq_file.txt | 9 +++++---- fs/seq_file.c | 16 ++++++++++++---- include/linux/seq_file.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/seq_file.txt b/Documentation/filesystems/seq_file.txt index 9de4303201e1..68571b8275d8 100644 --- a/Documentation/filesystems/seq_file.txt +++ b/Documentation/filesystems/seq_file.txt @@ -234,10 +234,11 @@ Here, the call to seq_open() takes the seq_operations structure we created before, and gets set up to iterate through the virtual file. On a successful open, seq_open() stores the struct seq_file pointer in -file->private_data. If you have an application where the same iterator can -be used for more than one file, you can store an arbitrary pointer in the -private field of the seq_file structure; that value can then be retrieved -by the iterator functions. +file->private_data. If you have an application where the same iterator +can be used for more than one file, you can store an arbitrary pointer +in the private field of the seq_file structure; that value can then be +retrieved by the iterator functions. Using the wrapper seq_open_data() +allows you to set the initial value for that field. There is also a wrapper function to seq_open() called seq_open_private(). It kmallocs a zero filled block of memory and stores a pointer to it in the diff --git a/fs/seq_file.c b/fs/seq_file.c index 4cc090b50cc5..c8c86660f6db 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -33,11 +33,12 @@ static void *seq_buf_alloc(unsigned long size) } /** - * seq_open - initialize sequential file + * seq_open_data - initialize sequential file * @file: file we initialize * @op: method table describing the sequence + * @data: initial value for ->private field * - * seq_open() sets @file, associating it with a sequence described + * seq_open_data() sets @file, associating it with a sequence described * by @op. @op->start() sets the iterator up and returns the first * element of sequence. @op->stop() shuts it down. @op->next() * returns the next element of sequence. @op->show() prints element @@ -45,10 +46,10 @@ static void *seq_buf_alloc(unsigned long size) * ERR_PTR(error). In the end of sequence they return %NULL. ->show() * returns 0 in case of success and negative number in case of error. * Returning SEQ_SKIP means "discard this element and move on". - * Note: seq_open() will allocate a struct seq_file and store its + * Note: seq_open_data() will allocate a struct seq_file and store its * pointer in @file->private_data. This pointer should not be modified. */ -int seq_open(struct file *file, const struct seq_operations *op) +int seq_open_data(struct file *file, const struct seq_operations *op, void *data) { struct seq_file *p; @@ -62,6 +63,7 @@ int seq_open(struct file *file, const struct seq_operations *op) mutex_init(&p->lock); p->op = op; + p->private = data; // No refcounting: the lifetime of 'p' is constrained // to the lifetime of the file. @@ -86,6 +88,12 @@ int seq_open(struct file *file, const struct seq_operations *op) file->f_mode &= ~FMODE_PWRITE; return 0; } +EXPORT_SYMBOL(seq_open_data); + +int seq_open(struct file *file, const struct seq_operations *op) +{ + return seq_open_data(file, op, NULL); +} EXPORT_SYMBOL(seq_open); static int traverse(struct seq_file *m, loff_t offset) diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index a121982af0f5..1142e39bfad2 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -107,6 +107,7 @@ void seq_pad(struct seq_file *m, char c); char *mangle_path(char *s, const char *p, const char *esc); int seq_open(struct file *, const struct seq_operations *); +int seq_open_data(struct file *, const struct seq_operations *, void *); ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); loff_t seq_lseek(struct file *, loff_t, int); int seq_release(struct inode *, struct file *); From patchwork Sat Aug 18 13:24:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10569549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C93A139B for ; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A2B42A84D for ; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D0AE2A836; Sat, 18 Aug 2018 13:25:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A602C2A836 for ; Sat, 18 Aug 2018 13:25:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726306AbeHRQdK (ORCPT ); Sat, 18 Aug 2018 12:33:10 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:37637 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbeHRQc2 (ORCPT ); Sat, 18 Aug 2018 12:32:28 -0400 Received: by mail-ed1-f68.google.com with SMTP id b10-v6so5979093eds.4 for ; Sat, 18 Aug 2018 06:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cL+amC/EhTEPmd41EAlHN3lVoQDtEfn6cmvZ4nKzOvo=; b=gzojv32NLct438Ce4rRbM6o630C3PjAaWL0pryspZG5NNJUFuplQufVtE/XCsXWWHO 0p+tTKVI+F3srVFC8f5+gw6rVlt6FK3dNTq2IyRPpOBtRs8ot38ULJw/OJZGWbS3jkau snFCK56WRhNUKAW/ezp6+oinhPJ9mcCJScVXk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cL+amC/EhTEPmd41EAlHN3lVoQDtEfn6cmvZ4nKzOvo=; b=T3uxjTvC6czqueQ5oW/Vbo2IxFiSOdRBAuPPY7RWTJg9RlKbZ9xKiJ5t/67zyhblfg mkIMJPAvj74A4yj9tINwS4u+ZTGQkCzG4yngvd+Oa4BtJYAk4PxythdR6WkJnpzFmgzb zFBj93/VN73RIjZTJyRZrkd4411tj6F6BMHwAbBUVbPGr3cS9J9/OdqnCCMDnYeNn7XD 90KGV9EiUlntCl9OVJSDKikHZmIsJifsnyVP2KhGfCllFjN+DJK1eD5mbaGe6Uvsuj6L AA6QL4BheCELB2wqG4Gkuw7/itJWyKIXzyPAlOj9jxMLJZVnBDbd9fPC0DT4+PTmcb2I kNaw== X-Gm-Message-State: AOUpUlFKRHkNnYZKFhBy70IKKzO/j4HOlpKGndRpD3DCQyyQEEO/W0Gm tXVwbzTOqajsT6Vj8oKbAnetJw== X-Google-Smtp-Source: AA+uWPwWun/4mMAkZ0+BhUifYyVaxX75RDphjddyTbgQoclYbztLcvqPXPweZIf/ImOcuJ5wUEvIVQ== X-Received: by 2002:a50:a2e5:: with SMTP id 92-v6mr48377120edm.106.1534598684438; Sat, 18 Aug 2018 06:24:44 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id a11-v6sm2739032edn.95.2018.08.18.06.24.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:24:44 -0700 (PDT) From: Rasmus Villemoes To: Alexander Viro Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 2/8] seq_file: use seq_open_data in single_open Date: Sat, 18 Aug 2018 15:24:28 +0200 Message-Id: <20180818132434.9515-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180818132434.9515-1-linux@rasmusvillemoes.dk> References: <20180818132434.9515-1-linux@rasmusvillemoes.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Avoid the somewhat hard to grok assignment by using the seq_open_data helper. Signed-off-by: Rasmus Villemoes --- fs/seq_file.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index c8c86660f6db..518a72e444d9 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -582,10 +582,8 @@ int single_open(struct file *file, int (*show)(struct seq_file *, void *), op->next = single_next; op->stop = single_stop; op->show = show; - res = seq_open(file, op); - if (!res) - ((struct seq_file *)file->private_data)->private = data; - else + res = seq_open_data(file, op, data); + if (res) kfree(op); } return res; From patchwork Sat Aug 18 13:24:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10569543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDB81139B for ; Sat, 18 Aug 2018 13:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC802A836 for ; Sat, 18 Aug 2018 13:25:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDECA2A854; Sat, 18 Aug 2018 13:25:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A71142A836 for ; Sat, 18 Aug 2018 13:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726255AbeHRQc3 (ORCPT ); Sat, 18 Aug 2018 12:32:29 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40103 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726326AbeHRQc3 (ORCPT ); Sat, 18 Aug 2018 12:32:29 -0400 Received: by mail-ed1-f66.google.com with SMTP id e19-v6so5979857edq.7 for ; Sat, 18 Aug 2018 06:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=viWNe3TzEQhqJk5ASZThGtH1epiz2Jr0E6XW1xgqJ1E=; b=Ubd1Wxfn/t83uXAwrSk3edjWwuxwYXUxXQ35mI0p0elMUodrtwoBBN7Ufof+i2mhRZ loLlOjhKiG/bKM4DqbhzBCrkmE45BgEhgTJD461AsmeDFUsOH1Zu/ZMgfwdlIZ20Cv0i y30In/uTeo7fR1VTdwwjwS66D1TXI+UO/d0mw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=viWNe3TzEQhqJk5ASZThGtH1epiz2Jr0E6XW1xgqJ1E=; b=m5dyL3rul8KCway0SwCk1yB5FLbcDXAzptUJEZBtayIS10ZDRsDx4G10VKtsDZjlgI anZ12DfKahm4I8U58MDlOljXy6lheV3E4wYAGikpGlUS3+Ks5tTdvWy5TxXdVFiWu5DO cQKsw11XGnmY8+xQsCrrAZred0bvxQsLXUNC3cINCQB+gbC7NQktTeQX7Tc/Cm9fvK+v hoHdW5sdkvZ4aPcqtq6LD2D3nWQL03nPScrLLpdmanzc2kWD5wJKG9zLwMGRqiug9W7T ahuyQx+bEj/j2l9Vhq5HnDdFVzwI4bgROpEHbQYl0xcAg342oEsLvKPKo6duTnwznQXD XOJQ== X-Gm-Message-State: AOUpUlECeUa1TEi3+piH+biEkOqg0kv5pZgjc2AjhcTZM//XGpU6nkNZ YMWJYQua7sUvNxkCj9p2b1SGHA== X-Google-Smtp-Source: AA+uWPz5qxBKZyaYD6PX6u+TTVwLruGHkOkAsYV+xrLqTdzaiCl7D53LtbJlcwACWCfsi4SW7pCS6g== X-Received: by 2002:a50:de8e:: with SMTP id c14-v6mr46269874edl.196.1534598685509; Sat, 18 Aug 2018 06:24:45 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id a11-v6sm2739032edn.95.2018.08.18.06.24.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:24:45 -0700 (PDT) From: Rasmus Villemoes To: Alexander Viro Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/8] seq_file: use seq_open_data in __seq_open_private Date: Sat, 18 Aug 2018 15:24:29 +0200 Message-Id: <20180818132434.9515-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180818132434.9515-1-linux@rasmusvillemoes.dk> References: <20180818132434.9515-1-linux@rasmusvillemoes.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Rasmus Villemoes --- fs/seq_file.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 518a72e444d9..5cc4670294e7 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -632,18 +632,15 @@ void *__seq_open_private(struct file *f, const struct seq_operations *ops, { int rc; void *private; - struct seq_file *seq; private = kzalloc(psize, GFP_KERNEL_ACCOUNT); if (private == NULL) goto out; - rc = seq_open(f, ops); + rc = seq_open_data(f, ops, private); if (rc < 0) goto out_free; - seq = f->private_data; - seq->private = private; return private; out_free: From patchwork Sat Aug 18 13:24:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10569545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A462614E1 for ; Sat, 18 Aug 2018 13:25:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93F942A836 for ; Sat, 18 Aug 2018 13:25:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 885842A84D; Sat, 18 Aug 2018 13:25:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D7F2A839 for ; Sat, 18 Aug 2018 13:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbeHRQca (ORCPT ); Sat, 18 Aug 2018 12:32:30 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:41126 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbeHRQca (ORCPT ); Sat, 18 Aug 2018 12:32:30 -0400 Received: by mail-ed1-f66.google.com with SMTP id s24-v6so5977782edr.8 for ; Sat, 18 Aug 2018 06:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yt93BPLDfVjLkUZ///kdCBdc5hre/vMNKZw/LDzwSvI=; b=KvsDijvkr6QtIquQGd6xj2KXcMk8QQaYKVYBpdt3i0Qha/dwkRt1vTf63t5qHAsUwA lZOzUucVwlkTyx7fYh7qMqh1/5gG4yxUd3pUnrZ6rsgGhftF5P8YnsQzTjne7WhmGGa0 6ekB41z14+e/qamzYMN1vACauHUZfd0RwaKxA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Yt93BPLDfVjLkUZ///kdCBdc5hre/vMNKZw/LDzwSvI=; b=RwTcQIyiBLZ4t7XkylWoSllSJzDHp+TF80FQsCpv+s1O0AsgnZWJKWxH3TN0BY3Na4 mY9H48aSKSwWHCLq220jmJsaY1Nh+VPri7mWtE4/rXGP/JYx42+INdFEjlEZh8KUxCzF Il2c1lO8B7KZ/oTrE0dzs0Jy7KcOmODAeTv9Gc6ZtneMwyxfRzyDOCVysC+TPgiqa0HS wqiiKyFh8xwGq5MkoY1uTr1R6O6XUAXsLrWVabwacWQ1OqU1xKgSV3iL4LxFpgqn7+e7 j7x5qu4rMX8ghqpLtqBBuKUKAiiI6LUqIbFvi8ud1Bp4W9gxIf5mXLquKD3DuSbzU9Kj B4XQ== X-Gm-Message-State: AOUpUlFmAOrMnirosrZayjf2i78bCbNvHe2VhkmLN6ppx3IflsC01kx7 mfGV731ZuCC5YiTCfAjFCg+iDg== X-Google-Smtp-Source: AA+uWPwTjsVya5cUtMkFivpgZu3z7xQo563C9lNVCFsSlQxFDSMqvljDtzIK/4Nz2wRixqFLw21bDg== X-Received: by 2002:a50:b822:: with SMTP id j31-v6mr46211244ede.76.1534598686461; Sat, 18 Aug 2018 06:24:46 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id a11-v6sm2739032edn.95.2018.08.18.06.24.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:24:45 -0700 (PDT) From: Rasmus Villemoes To: Alexey Dobriyan Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 4/8] proc: use seq_open_data() in proc_id_map_open() Date: Sat, 18 Aug 2018 15:24:30 +0200 Message-Id: <20180818132434.9515-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180818132434.9515-1-linux@rasmusvillemoes.dk> References: <20180818132434.9515-1-linux@rasmusvillemoes.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify the code slightly by using the seq_open_data helper. Signed-off-by: Rasmus Villemoes --- Depends on 1/8 introducing seq_open_data. fs/proc/base.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index aaffc0c30216..32ed72c44412 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2747,7 +2747,6 @@ static int proc_id_map_open(struct inode *inode, struct file *file, { struct user_namespace *ns = NULL; struct task_struct *task; - struct seq_file *seq; int ret = -EINVAL; task = get_proc_task(inode); @@ -2758,19 +2757,11 @@ static int proc_id_map_open(struct inode *inode, struct file *file, put_task_struct(task); } if (!ns) - goto err; + return ret; - ret = seq_open(file, seq_ops); + ret = seq_open_data(file, seq_ops, ns); if (ret) - goto err_put_ns; - - seq = file->private_data; - seq->private = ns; - - return 0; -err_put_ns: - put_user_ns(ns); -err: + put_user_ns(ns); return ret; }