Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755248AbaDNLtT (ORCPT ); Mon, 14 Apr 2014 07:49:19 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:49871 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754880AbaDNLtL (ORCPT ); Mon, 14 Apr 2014 07:49:11 -0400 X-AuditID: cbfee61a-b7fb26d00000724f-d0-534bcb36c151 From: Robert Baldyga Cc: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, rob@landley.net, myungjoo.ham@samsung.com, cw00.choi@samsung.com, dbaryshkov@gmail.com, dwmw2@infradead.org, balbi@ti.com, gregkh@linuxfoundation.org, grant.likely@linaro.org, ldewangan@nvidia.com, kishon@ti.com, gg@slimlogic.co.uk, anton@enomsg.org, jonghwa3.lee@samsung.com, rongjun.ying@csr.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, patches@opensource.wolfsonmicro.com, linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, aaro.koskinen@iki.fi, m.szyprowski@samsung.com, t.figa@samsung.com, Robert Baldyga Subject: [PATCH v2 08/13] extcon: extcon-class: simplify extcon_updata_state() function Date: Mon, 14 Apr 2014 13:46:19 +0200 Message-id: <1397475984-28001-9-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1397475984-28001-1-git-send-email-r.baldyga@samsung.com> References: <1397475984-28001-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWRa0hTYRjHe3cuO65Wh2l2tLIYCiZmGSIvZCWV8YIYhoQVlS49zNWmY1PR iFos865TKTMt7/ctydSclM45qNDMsLRSK0utmZmGY5G3nNK33/P7/3meDw+FCVpwZ0oSHcsq okVSIcnDu5e+0rt9uwND9lZV7YDa7/6ws3kX7Px0DQ7OfSNg7tgvDBabegmYU5uHweypUgJm Nx2FhoVWANXlDSTsnawFMPXlGAb7xjNIWNlej8PSmxU47G8rImFhRTYOy6qSMDhW2sOBOtMI F1YOvubAoes1JKz+uUxCTb4Oh5+79Fz4wJyPw6SnJi5s71sgYMOdH7i/C9Le1wLUn5XJQW36 IgJpsn8DpL87wkW11XMk6rKU4uhRjQdqrEsl0WR9AYGGB56QqOOelosy1dMkMufMk0hvVXFR VlMdCLY/w/OLZKWSeFax52A4L8rYk4zLh10TrANvSBXo2p4GKIqhfZjZd/w0YLeCjkzfxwYy DfAoAV0GmJL3Kdy1IZnDpFvLga1F0p5Mk1Wzyg40xpTcerXKGD1OMI//HLAttadPMwPTYpvG aTcms76Ka9N8OoBJWQxdO7uTKcr1szXs6GNMZ8EiZmPBSsOgHsI0gF8C1tWBzaw8Qq68IJZ5 eylFMmVctNgrIkbWCFa/OeHcCmpV0AhoCgg38FOKAkMEhChemSgzAobChA78gOYVxY8UJV5m FTFhijgpqzSCrRQu3MI3JO0/IaDFolj2EsvKWcX/lEPZOauAozL0WfhxyynToeX0squFqgkL 7/jfhI4PLyxRFvXofIT8MOU+5E6byzpzT+7jmfTSxeAw642Z3imXTJ/Z4SuqNsN6AXNE7u5a XPk80rRkbNnog247vTWfPe9UEKSZEaSfI9wcdNIgXUWqpeLiaN7DQF3GF29Pia9s2ya/0RSJ EFdGibw9MIVS9A9PyoaVyQIAAA== To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch simplifies extcon_updata_state() function. There is greatly simplified kobject_uevent preparation. Also meaning of variable passed to raw_notifier_call_chain() (and in effect to _call_per_cable()) has changed. Now positions on ones in variable 'val' in _call_per_cable() indicates numbers of cables which changed their status. It allowed to simplify also _call_per_cable() function. Signed-off-by: Robert Baldyga --- drivers/extcon/extcon-class.c | 81 ++++++++++++++++------------------------- include/linux/extcon.h | 1 - 2 files changed, 31 insertions(+), 51 deletions(-) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index e9e5e85..13993c6 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -206,59 +206,48 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) { char name_buf[120]; char state_buf[120]; - char *prop_buf; + char *tmp; char *envp[3]; int env_offset = 0; int length; unsigned long flags; + u32 change; spin_lock_irqsave(&edev->lock, flags); - if (edev->state != ((edev->state & ~mask) | (state & mask))) { - u32 old_state = edev->state; - - if (check_mutually_exclusive(edev, (edev->state & ~mask) | - (state & mask))) { + change = (edev->state & mask) ^ (state & mask); + if (change) { + if (check_mutually_exclusive(edev, edev->state ^ change)) { spin_unlock_irqrestore(&edev->lock, flags); return -EPERM; } - edev->state &= ~mask; - edev->state |= state & mask; - - raw_notifier_call_chain(&edev->nh, old_state, edev); - /* This could be in interrupt handler */ - prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); - if (prop_buf) { - length = name_show(&edev->dev, NULL, prop_buf); - if (length > 0) { - if (prop_buf[length - 1] == '\n') - prop_buf[length - 1] = 0; - snprintf(name_buf, sizeof(name_buf), - "NAME=%s", prop_buf); - envp[env_offset++] = name_buf; - } - length = state_show(&edev->dev, NULL, prop_buf); - if (length > 0) { - if (prop_buf[length - 1] == '\n') - prop_buf[length - 1] = 0; - snprintf(state_buf, sizeof(state_buf), - "STATE=%s", prop_buf); - envp[env_offset++] = state_buf; - } - envp[env_offset] = NULL; - /* Unlock early before uevent */ - spin_unlock_irqrestore(&edev->lock, flags); + edev->state ^= change; - kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); - free_page((unsigned long)prop_buf); - } else { - /* Unlock early before uevent */ - spin_unlock_irqrestore(&edev->lock, flags); + raw_notifier_call_chain(&edev->nh, change, edev); + + tmp = name_buf + sprintf(name_buf, "NAME="); + length = name_show(&edev->dev, NULL, tmp); + if (length > 0) { + if (tmp[length - 1] == '\n') + tmp[length - 1] = 0; + envp[env_offset++] = name_buf; + } - dev_err(&edev->dev, "out of memory in extcon_set_state\n"); - kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE); + tmp = state_buf + sprintf(state_buf, "STATE="); + length = state_show(&edev->dev, NULL, tmp); + if (length > 0) { + if (tmp[length - 1] == '\n') + tmp[length - 1] = 0; + envp[env_offset++] = state_buf; } + + envp[env_offset] = NULL; + + /* Unlock early before uevent */ + spin_unlock_irqrestore(&edev->lock, flags); + + kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); } else { /* No changes */ spin_unlock_irqrestore(&edev->lock, flags); @@ -511,18 +500,10 @@ static int _call_per_cable(struct notifier_block *nb, unsigned long val, { struct extcon_cable_nb *obj = container_of(nb, struct extcon_cable_nb, internal_nb); - struct extcon_dev *edev = ptr; - - if ((val & (1 << obj->cable->cable_index)) != - (edev->state & (1 << obj->cable->cable_index))) { - bool cable_state = true; - - obj->previous_value = val; - - if (val & (1 << obj->cable->cable_index)) - cable_state = false; - return obj->notifier_function(obj, cable_state); + if ((1 << obj->cable->cable_index) & val) { + int state = extcon_get_cable_state(obj->cable); + return obj->notifier_function(obj, !!state); } return NOTIFY_OK; diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 28e60fb..8792ca2 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -177,7 +177,6 @@ typedef int (*extcon_notifier_fn_t)(struct extcon_cable_nb *cable_nb, */ struct extcon_cable_nb { struct notifier_block internal_nb; - unsigned long previous_value; extcon_notifier_fn_t notifier_function; struct extcon_cable *cable; }; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/