From patchwork Mon Feb 22 16:36:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= X-Patchwork-Id: 8379881 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DBF25C0553 for ; Mon, 22 Feb 2016 16:40:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 139DA204FC for ; Mon, 22 Feb 2016 16:40:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31DBB204EB for ; Mon, 22 Feb 2016 16:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754539AbcBVQj7 (ORCPT ); Mon, 22 Feb 2016 11:39:59 -0500 Received: from mail-qk0-f174.google.com ([209.85.220.174]:33486 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752811AbcBVQhF (ORCPT ); Mon, 22 Feb 2016 11:37:05 -0500 Received: by mail-qk0-f174.google.com with SMTP id s5so57711783qkd.0; Mon, 22 Feb 2016 08:37:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=enrbxoh5BqXSgTZgphOg2vf5G953oWJ8bqOovCb1a84=; b=nn9prfhQ7psQqIO1vUNE8HuEKkHd0jaCoBl6sca0TY/3Ju2yI2CHebLEjtg52RAdZu 17tFQmgKWRqEXotUnu9zJV+Ts/KFxyB2CNwp7sNgRCsJd4jjIV3ZSlnmJo1VtNJo+r2H SUweYQIge62JJ8yR/m5WtRl3Kgeyw0cjGScUSNN5bqpEnZoFAnQyg1CXbCpYJ5rHcXlG PalAOqva4I589abuZki4uc2ZnW4sOdUG1/u6ITs0FpbesFbuzUMzrRTiH3GaxWqWLtd7 YKZ3WWkq75dbHk8VYvK9j6TQeJPklXp1PH5EM54Ko715cPyoM2mzhZUMJ4b8wG2T570l HWqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=enrbxoh5BqXSgTZgphOg2vf5G953oWJ8bqOovCb1a84=; b=BpBCui4GdL/IZAnTGIRHCotszS52knuA1eYy4rXnyCpwmvH2lvHaYEOphWFPtHhNw6 xAYs+yTIbUSPhQSTHtznwyvTtkKneghYjLx4c0Ve1vspZOTfqNVrGJp71DSr9Zdgbr0e WJT4+H3i48O1yvKVbM3xTGS2wf5RlE6E8u9LocHkkYY/5DdRm6DDPDq6goBOLl5Ovu4X pmD1WyOGhxEROMNwto1ndPDnU4/HuYqlLYw2lMIRWXnDK5h9CQPAxu5ioMb7AGxO5OvP ZadjvbN6gY8pbrY70oiiUCTJdZVd6D0oczoi5xcAdNBLdv/eNe5ISomJ2iHDRtTE6jXr Kk1g== X-Gm-Message-State: AG10YOROF7LrEbHoJUIjdVM7npq9MyU/oD5uKg0ALvZfM5riSJYrR5h/H3UvBDOZU3umEA== X-Received: by 10.55.81.87 with SMTP id f84mr35261994qkb.10.1456159024988; Mon, 22 Feb 2016 08:37:04 -0800 (PST) Received: from kiddo.endlessm-sf.com (c-98-239-150-235.hsd1.wv.comcast.net. [98.239.150.235]) by smtp.gmail.com with ESMTPSA id j67sm6874669qgj.35.2016.02.22.08.37.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 08:37:04 -0800 (PST) From: "=?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?=" X-Google-Original-From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= To: Johannes Berg Cc: "David S. Miller" , Darren Hart , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com, =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Subject: [PATCHv2 08/10] rfkill: Use switch to demux userspace operations Date: Mon, 22 Feb 2016 11:36:39 -0500 Message-Id: <1456159001-20307-9-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> References: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using a switch to handle different ev.op values in rfkill_fop_write() makes the code easier to extend, as out-of-range values can always be handled by the default case. Signed-off-by: João Paulo Rechi Vita --- net/rfkill/core.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 50b538b..04d7fa1 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -1185,6 +1185,7 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, { struct rfkill *rfkill; struct rfkill_event ev; + int ret = 0; /* we don't need the 'hard' variable but accept it */ if (count < RFKILL_EVENT_SIZE_V1 - 1) @@ -1199,29 +1200,32 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, if (copy_from_user(&ev, buf, count)) return -EFAULT; - if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL) - return -EINVAL; - if (ev.type >= NUM_RFKILL_TYPES) return -EINVAL; mutex_lock(&rfkill_global_mutex); - if (ev.op == RFKILL_OP_CHANGE_ALL) + switch (ev.op) { + case RFKILL_OP_CHANGE_ALL: rfkill_update_global_state(ev.type, ev.soft); - - list_for_each_entry(rfkill, &rfkill_list, node) { - if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) - continue; - - if (rfkill->type != ev.type && ev.type != RFKILL_TYPE_ALL) - continue; - - rfkill_set_block(rfkill, ev.soft); + list_for_each_entry(rfkill, &rfkill_list, node) + if (rfkill->type == ev.type || + ev.type == RFKILL_TYPE_ALL) + rfkill_set_block(rfkill, ev.soft); + break; + case RFKILL_OP_CHANGE: + list_for_each_entry(rfkill, &rfkill_list, node) + if (rfkill->idx == ev.idx && rfkill->type == ev.type) + rfkill_set_block(rfkill, ev.soft); + break; + default: + ret = -EINVAL; + break; } + mutex_unlock(&rfkill_global_mutex); - return count; + return ret ? ret : count; } static int rfkill_fop_release(struct inode *inode, struct file *file)