From patchwork Mon Jan 29 23:15:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Limonciello, Mario" X-Patchwork-Id: 10191057 X-Patchwork-Delegate: andy.shevchenko@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5792360375 for ; Mon, 29 Jan 2018 23:16:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5165C2876A for ; Mon, 29 Jan 2018 23:16:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45BF5288BD; Mon, 29 Jan 2018 23:16:18 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 814062876A for ; Mon, 29 Jan 2018 23:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751363AbeA2XQR (ORCPT ); Mon, 29 Jan 2018 18:16:17 -0500 Received: from esa4.dell-outbound.iphmx.com ([68.232.149.214]:10590 "EHLO esa4.dell-outbound.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751357AbeA2XQQ (ORCPT ); Mon, 29 Jan 2018 18:16:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dell.com; i=@dell.com; q=dns/txt; s=smtpout; t=1517267776; x=1548803776; h=from:to:cc:subject:date:message-id; bh=uIcsVGzD5eyojoke/hgsXBreeYxbhIILdmMeGjZcJMs=; b=dezt5eIimBsjl0ADOjAFSx0whdUspVFF0zhhW1wwmmOgK2aSFWONXH5Q Ys8Z1z83h4znPDXr1oSyGadmWjwW24Z7d6QNQn7J6SpyX/NJmFziiN+qH jjGQJzI+I/UTIqdjuxawK4JsBSEUQkSs08yD2u5VRKV4yc3KFlrXdbhXb 4=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2GoAQB7qm9amGOa6ERUCBoBAQEBAQIBA?= =?us-ascii?q?QEBCAEBAQGFHSicb4sVkEgKhTuCO1gUAQEBAQEBAQECAQIQAQEBAQEICwsGKC+?= =?us-ascii?q?COCQBgnVSTzM8ARKKHQMVp3k6hzsNgx0yhFSCFYFXiAFEBIFKgn8MgxYFk1KQB?= =?us-ascii?q?T2CSo4XhQYClCUCjiiJOoE8NoFzcIJ8ggUBTxAMgiVZjxcBAQE?= X-IPAS-Result: =?us-ascii?q?A2GoAQB7qm9amGOa6ERUCBoBAQEBAQIBAQEBCAEBAQGFHSi?= =?us-ascii?q?cb4sVkEgKhTuCO1gUAQEBAQEBAQECAQIQAQEBAQEICwsGKC+COCQBgnVSTzM8A?= =?us-ascii?q?RKKHQMVp3k6hzsNgx0yhFSCFYFXiAFEBIFKgn8MgxYFk1KQBT2CSo4XhQYClCU?= =?us-ascii?q?CjiiJOoE8NoFzcIJ8ggUBTxAMgiVZjxcBAQE?= Received: from esa6.dell-outbound2.iphmx.com ([68.232.154.99]) by esa4.dell-outbound.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2018 17:16:14 -0600 Received: from ausc60ps301.us.dell.com ([143.166.148.206]) by esa6.dell-outbound2.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2018 05:16:14 +0600 X-LoopCount0: from 10.208.86.39 X-IronPort-AV: E=Sophos;i="5.46,433,1511848800"; d="scan'208";a="1090782135" X-DLP: DLP_GlobalPCIDSS From: Mario Limonciello To: dvhart@infradead.org, Andy Shevchenko Cc: pali.rohar@gmail.com, LKML , platform-driver-x86@vger.kernel.org, Mario Limonciello Subject: [PATCH] platform/x86: dell-laptop: Guard SMBIOS calls with a mutex Date: Mon, 29 Jan 2018 17:15:56 -0600 Message-Id: <1517267756-29878-1-git-send-email-mario.limonciello@dell.com> X-Mailer: git-send-email 2.7.4 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Suggested-by: Pali Rohar Signed-off-by: Mario Limonciello --- drivers/platform/x86/dell-laptop.c | 67 ++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c index fc2dfc8..f8e2bd8 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell-laptop.c @@ -85,6 +85,7 @@ static struct rfkill *wifi_rfkill; static struct rfkill *bluetooth_rfkill; static struct rfkill *wwan_rfkill; static bool force_rfkill; +static DEFINE_MUTEX(buffer_mutex); module_param(force_rfkill, bool, 0444); MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); @@ -472,16 +473,17 @@ static int dell_rfkill_set(void *data, bool blocked) int status; int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); if (ret) - return ret; + goto out; status = buffer->output[1]; dell_set_arguments(0x2, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); if (ret) - return ret; + goto out; hwswitch = buffer->output[1]; /* If the hardware switch controls this radio, and the hardware @@ -492,6 +494,9 @@ static int dell_rfkill_set(void *data, bool blocked) dell_set_arguments(1 | (radio<<8) | (disable << 16), 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); + +out: + mutex_unlock(&buffer_mutex); return ret; } @@ -501,8 +506,10 @@ static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio, if (status & BIT(0)) { /* Has hw-switch, sync sw_state to BIOS */ int block = rfkill_blocked(rfkill); + mutex_lock(&buffer_mutex); dell_set_arguments(1 | (radio << 8) | (block << 16), 0, 0, 0); dell_send_request(CLASS_INFO, SELECT_RFKILL); + mutex_unlock(&buffer_mutex); } else { /* No hw-switch, sync BIOS state to sw_state */ rfkill_set_sw_state(rfkill, !!(status & BIT(radio + 16))); @@ -523,22 +530,24 @@ static void dell_rfkill_query(struct rfkill *rfkill, void *data) int status; int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); status = buffer->output[1]; - if (ret != 0 || !(status & BIT(0))) { - return; - } + if (ret != 0 || !(status & BIT(0))) + goto out; dell_set_arguments(0, 0x2, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); hwswitch = buffer->output[1]; if (ret != 0) - return; + goto out; dell_rfkill_update_hw_state(rfkill, radio, status, hwswitch); +out: + mutex_unlock(&buffer_mutex); } static const struct rfkill_ops dell_rfkill_ops = { @@ -555,16 +564,19 @@ static int dell_debugfs_show(struct seq_file *s, void *data) int status; int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); if (ret) - return ret; + goto out; status = buffer->output[1]; dell_set_arguments(0, 0x2, 0, 0); hwswitch_ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); - if (hwswitch_ret) - return hwswitch_ret; + if (hwswitch_ret) { + ret = hwswitch_ret; + goto out; + } hwswitch_state = buffer->output[1]; seq_printf(s, "return:\t%d\n", ret); @@ -628,7 +640,9 @@ static int dell_debugfs_show(struct seq_file *s, void *data) seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", (hwswitch_state & BIT(15)) >> 15); - return 0; +out: + mutex_unlock(&buffer_mutex); + return ret; } static int dell_debugfs_open(struct inode *inode, struct file *file) @@ -650,12 +664,13 @@ static void dell_update_rfkill(struct work_struct *ignored) int status; int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); status = buffer->output[1]; if (ret != 0) - return; + goto out; dell_set_arguments(0, 0x2, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); @@ -676,6 +691,8 @@ static void dell_update_rfkill(struct work_struct *ignored) dell_rfkill_update_hw_state(wwan_rfkill, 3, status, hwswitch); dell_rfkill_update_sw_state(wwan_rfkill, 3, status); } +out: + mutex_unlock(&buffer_mutex); } static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); @@ -734,9 +751,11 @@ static int __init dell_setup_rfkill(void) if (!force_rfkill && !whitelisted) return 0; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_INFO, SELECT_RFKILL); status = buffer->output[1]; + mutex_unlock(&buffer_mutex); /* dell wireless info smbios call is not supported */ if (ret != 0) @@ -896,11 +915,13 @@ static int dell_send_intensity(struct backlight_device *bd) if (!token) return -ENODEV; + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, bd->props.brightness, 0, 0); if (power_supply_is_system_supplied() > 0) ret = dell_send_request(CLASS_TOKEN_WRITE, SELECT_TOKEN_AC); else ret = dell_send_request(CLASS_TOKEN_WRITE, SELECT_TOKEN_BAT); + mutex_unlock(&buffer_mutex); return ret; } @@ -914,6 +935,7 @@ static int dell_get_intensity(struct backlight_device *bd) if (!token) return -ENODEV; + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, 0, 0, 0); if (power_supply_is_system_supplied() > 0) ret = dell_send_request(CLASS_TOKEN_READ, SELECT_TOKEN_AC); @@ -922,6 +944,8 @@ static int dell_get_intensity(struct backlight_device *bd) if (ret == 0) ret = buffer->output[1]; + mutex_unlock(&buffer_mutex); + return ret; } @@ -1189,10 +1213,11 @@ static int kbd_get_info(struct kbd_info *info) u8 units; int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0, 0, 0, 0); ret = dell_send_request(CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT); if (ret) - return ret; + goto out; info->modes = buffer->output[1] & 0xFFFF; info->type = (buffer->output[1] >> 24) & 0xFF; @@ -1212,6 +1237,8 @@ static int kbd_get_info(struct kbd_info *info) if (units & BIT(3)) info->days = (buffer->output[3] >> 24) & 0xFF; +out: + mutex_unlock(&buffer_mutex); return ret; } @@ -1272,10 +1299,11 @@ static int kbd_get_state(struct kbd_state *state) { int ret; + mutex_lock(&buffer_mutex); dell_set_arguments(0x1, 0, 0, 0); ret = dell_send_request(CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT); if (ret) - return ret; + goto out; state->mode_bit = ffs(buffer->output[1] & 0xFFFF); if (state->mode_bit != 0) @@ -1289,7 +1317,8 @@ static int kbd_get_state(struct kbd_state *state) state->level = (buffer->output[2] >> 16) & 0xFF; state->timeout_value_ac = (buffer->output[2] >> 24) & 0x3F; state->timeout_unit_ac = (buffer->output[2] >> 30) & 0x3; - +out: + mutex_unlock(&buffer_mutex); return ret; } @@ -1307,8 +1336,10 @@ static int kbd_set_state(struct kbd_state *state) input2 |= (state->level & 0xFF) << 16; input2 |= (state->timeout_value_ac & 0x3F) << 24; input2 |= (state->timeout_unit_ac & 0x3) << 30; + mutex_lock(&buffer_mutex); dell_set_arguments(0x2, input1, input2, 0); ret = dell_send_request(CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT); + mutex_unlock(&buffer_mutex); return ret; } @@ -1345,8 +1376,10 @@ static int kbd_set_token_bit(u8 bit) if (!token) return -EINVAL; + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, token->value, 0, 0); ret = dell_send_request(CLASS_TOKEN_WRITE, SELECT_TOKEN_STD); + mutex_unlock(&buffer_mutex); return ret; } @@ -1364,9 +1397,11 @@ static int kbd_get_token_bit(u8 bit) if (!token) return -EINVAL; + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, 0, 0, 0); ret = dell_send_request(CLASS_TOKEN_READ, SELECT_TOKEN_STD); val = buffer->output[1]; + mutex_unlock(&buffer_mutex); if (ret) return ret; @@ -2114,8 +2149,10 @@ int dell_micmute_led_set(int state) if (!token) return -ENODEV; + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, token->value, 0, 0); dell_send_request(CLASS_TOKEN_WRITE, SELECT_TOKEN_STD); + mutex_unlock(&buffer_mutex); return state; } @@ -2177,10 +2214,12 @@ static int __init dell_init(void) token = dell_smbios_find_token(BRIGHTNESS_TOKEN); if (token) { + mutex_lock(&buffer_mutex); dell_set_arguments(token->location, 0, 0, 0); ret = dell_send_request(CLASS_TOKEN_READ, SELECT_TOKEN_AC); if (ret) max_intensity = buffer->output[3]; + mutex_unlock(&buffer_mutex); } if (max_intensity) {