From patchwork Mon Jul 31 13:49:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 9871867 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 7031060375 for ; Mon, 31 Jul 2017 13:50:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D39628405 for ; Mon, 31 Jul 2017 13:50:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41EDE285CB; Mon, 31 Jul 2017 13:50:08 +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.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, 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 D194D28405 for ; Mon, 31 Jul 2017 13:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751735AbdGaNuE (ORCPT ); Mon, 31 Jul 2017 09:50:04 -0400 Received: from mout.gmx.net ([212.227.15.19]:53726 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750987AbdGaNuD (ORCPT ); Mon, 31 Jul 2017 09:50:03 -0400 Received: from ls3530.fritz.box ([193.159.19.154]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lt1eU-1diPTK3Mi2-012ad1; Mon, 31 Jul 2017 15:49:56 +0200 Date: Mon, 31 Jul 2017 15:49:54 +0200 From: Helge Deller To: linux-parisc@vger.kernel.org, James Bottomley , John David Anglin Subject: [PATCH] parisc: pdc_stable: Fix locking when creating sysfs links Message-ID: <20170731134954.GA2466@ls3530.fritz.box> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) X-Provags-ID: V03:K0:XuHCquicpLF0VUP/4Vo5pECo+JOro4azuq31Qvnxong73gqVVio 7fzpmHnhqff2L/d9QMxsDaGEXPyHsjqMnB4sDAhFn5MRaHvfOqTr78WtNhFaqn18uuJVEd+ M6VwthrVOfEk3XpBJOHCmdWaUTCArVwFYrXuqaKg25v76U8aKvlmJLu/pr2bErlpM99WWUo 8rllanfCVJAItLXVZKsew== X-UI-Out-Filterresults: notjunk:1; V01:K0:nDH+9srSUfw=:eQrvt9pKlNQRjihPxr7Kmr X5qVCkU3hIgDmuJibhzKyMlhNjp6QXZSYwgcPPysc9gqkV+UfZ/xXes2QDDXvGiOA8qt0KAx+ kE8pZdXwxqBIl2AjDA4O840lQDbNfgfPFSH1hcaGAcW3fhpM/nNc/jEQvh4g5A5SCSpWz1ONw rKWwWG7aekgx4SyKa4HjipkDvBF4/2OTiGwUGri9BKKysAnW+4gSNXI/YSFj/XK/VsE9WUogc dj6VF+dsc9TEUIEkAqQlo1+yccgNNe91nCpCEm/GNJw9niwCUr8xTk1ENC608i8eJzWJFxfwP kGXg9CZgdVyOTDcKXmSVJFJWUSwi8HtLNeKPJ2rPiq9tZJai9KdWNuvcYoOpJ/OXnzNlnw4/B gZm1HfnLsZIHdt05R44BBj456opnt9HNoOQvlGqFf+n1urg/Ps0OuIT6FKGrM3yC2APTQQoag EmNhHlnvdp9OkUUK67k/dWuzFFH3tMelUbzeHOv9tSkwsGdx6cQnQCUY/rg0MdrqNbk8RgMbV hSvVpdB3n0fETp5XxElY2pZq60s81Op6vuu1tti4zlFJSuChwZ8Nm49uxqdDa8wzst9c8x/EE KsNpsij9r4+AShZdPDTYCd4zW/rzUoJarQX8O46gsLnXBY3852dLSj3Vb1P5fOl9C4VO9RFqW 3hRKAnPpOxPdkaUWWnJOYb9qebK0Nvfn91W6mgcHaCncpu2T5tIgEjtAMBqX4Xs9WUGJMUfe6 pNVGZC95vAUntCrFMWso9dlFhp0M0Y01/tm8rWAd8b64VyDi68MO4Qppk0MoFmSZD2fRV4few e5YfCShgmU4bHn+lwnbt+IgfuYizw== Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: James Bottomley There's no need to take the write lock when creating sysfs links. This patch fixes the following BUG: BUG: sleeping function called from invalid context at mm/slab.h:416 in_atomic(): 1, irqs_disabled(): 0, pid: 1, name: swapper/0 CPU: 2 PID: 1 Comm: swapper/0 Not tainted 4.13.0-rc2-00110-g0b5477d9dabd #111 Backtrace: [<0000000040217ac8>] show_stack+0x20/0x38 [<00000000406fbbb0>] dump_stack+0xb0/0x128 [<0000000040274090>] ___might_sleep+0x180/0x1b8 [<0000000040274144>] __might_sleep+0x7c/0xe8 [<0000000040373874>] kmem_cache_alloc+0x14c/0x1e0 [<0000000040419514>] __kernfs_new_node+0x84/0x1b8 [<000000004041b09c>] kernfs_new_node+0x3c/0x78 [<000000004041e040>] kernfs_create_link+0x40/0xd8 [<000000004041f320>] sysfs_do_create_link_sd.isra.0+0xb0/0x130 [<000000004041f3d4>] sysfs_create_link+0x34/0x58 [<000000004011b4a4>] pdc_stable_init+0x2c4/0x458 [<0000000040200250>] do_one_initcall+0x70/0x1d8 [<0000000040101644>] kernel_init_freeable+0x27c/0x390 [<000000004020be44>] kernel_init+0x24/0x1c0 Signed-off-by: James Bottomley Reported-by: Meelis Roos --- To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c index 7147aa5..b1ff46f 100644 --- a/drivers/parisc/pdc_stable.c +++ b/drivers/parisc/pdc_stable.c @@ -333,11 +333,11 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun /* Update the symlink to the real device */ sysfs_remove_link(&entry->kobj, "device"); + write_unlock(&entry->rw_lock); + ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); WARN_ON(ret); - write_unlock(&entry->rw_lock); - printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n", entry->name, buf); @@ -998,6 +998,7 @@ pdcs_register_pathentries(void) /* kobject is now registered */ write_lock(&entry->rw_lock); entry->ready = 2; + write_unlock(&entry->rw_lock); /* Add a nice symlink to the real device */ if (entry->dev) { @@ -1005,7 +1006,6 @@ pdcs_register_pathentries(void) WARN_ON(err); } - write_unlock(&entry->rw_lock); kobject_uevent(&entry->kobj, KOBJ_ADD); }