Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4313417ybc; Fri, 22 Nov 2019 00:26:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyWHPSGVuyxPaSwxBG9xjJB0pXvmRcxXC+3NuyGORhgcmmUs+RF7jv3vc7ANggQpPzQvleY X-Received: by 2002:a17:906:b819:: with SMTP id dv25mr2202892ejb.182.1574411166609; Fri, 22 Nov 2019 00:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574411166; cv=none; d=google.com; s=arc-20160816; b=UKc2yFPMmN7VNy8b6s/zaK96UDBLx9ILhFsIWFA5ole5THclUrGtrPTZf8Al/TSVvY lwztHgUYxWq4Ji0yIosJjO/UGxUCMTWkMMGqNIYZDlyHbFS1UPyu13CRsJE/N3EL4l/y J76VLf7iv26oiF3EPknoRg+oCEtldVXW+65fwn+lY1xPUQgcB+k8z+/Fr5TCY537mkvs g10b2Jp43Bpe9dbOIUT5k3V9P1uax46YPkMAB98TnTfEqy1UPTSGTOQRahiWOmVTNnar qnN6bMF5QbW0xk1Id1/Bh23g1DCt8H9ZBwU9HGSSjs9+7pDhIXaE/hfduXGEf0UH0krz b4Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=HuKhvLW1s5rx5DxOanNTTAetlw50mMzKDFTu54n2b/M=; b=w7qLKSoW86sO7ApXeNwiXWG8RMieKQ4DNaNhSwOuVV6H6vwnNA9Ihg5lt5PPjSvYN/ oyeRO+pL1P1pCuLUVe/bJoZ2YoZgPdNKOLk/uCcTOwfAziGd8SLMvuPQKdiLzFibz6o7 Zez2W/4Az/vO9ZACKutpby1c3frjisfl3MCoohRvGG0vdWQW7w51GM22LV3WoS6TKpEw 9uDDJ/9hcHXqSvaYjCf/gx61z2VHsFDkl41Iqpvl9g3RsuJ3wtMMmSFBLJdDsdkUPBfe yP0UbTCq5M+7+TNyo6fENGAEE3q3KmOgZijyzjvhC2Qwb2RyzrQ5pwHcsGczNxRM+NVe wVUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mj12si3806513ejb.186.2019.11.22.00.25.42; Fri, 22 Nov 2019 00:26:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfKVIYY (ORCPT + 99 others); Fri, 22 Nov 2019 03:24:24 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60514 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYX (ORCPT ); Fri, 22 Nov 2019 03:24:23 -0500 IronPort-SDR: FGnyb6Lp5OvJwp+osvKOpEuR/AyqWiS6oT4m0rrRoKc9MvwGIe8XkTXSfpKmlzacdnIdoN46CZ VmuXEiWb0QuT7d5NfzCpyBEl5fpmOnctFObDXFcKiRXh42AqVOL6SJTvlZjvCsvev6YhXE3X33 y2uESeXnirpmhg/2cDDz2GiqS+2uAu2l3FnMGt1qnIgkus+K/ZuJurc6zqfnoN4U1eHCkTLBvW 7axRJDLlpS75XOgGRzjeqUmXXxqYAdjavfB6gHExCOB5AEIgxCD/LLiz4/n4L9rNmGSUjVqNKk eDs= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291094" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:13 -0800 IronPort-SDR: C3IfEUvY298/qipBdKiy3UCbbacTOf9HA5yUlE8UT8TnSfRaMJ3Da68IIPbzY3sHROgIBrjvMy 5qGYQGwsPBcaty00+milmYoYTRbqTbrtbScaszgf8fAXpvzTdn6+mqvAba8FNII40OplJBLBA4 PZTuE4HY78UsMNi/r/YGCkstszmA/hUlmsmR3HuyS7rKoGr94oNFcoapXxGaVwl26pIoKUJYMZ NMJY/RlI5ZAnFByX649egjb/duirt8lR+9Z+1mcr3DIGWwu1jNNk2p/1r9QH2/p2Bdnr7KCZbW tC0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 02/48] Input: atmel_mxt_ts - rework sysfs init/remove Date: Fri, 22 Nov 2019 17:23:16 +0900 Message-ID: <20191122082402.18173-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Dyer An error in the sysfs init may otherwise interfere with the async return from the firmware loader Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3114584ae77c2b03b6dad87174f010d002e9c05d) [gdavis: Forward port and fixup conflicts. Also fixed sysfs leaks in both the mxt_initialize() and mxt_probe() error return cases.] Signed-off-by: George G. Davis [jiada: keep call mxt_initialize() before sysfs creation] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 6e758af343ea..ffe8a80f4d0a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2086,10 +2086,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) return 0; err_free_mem: + data->input_dev = NULL; input_free_device(input_dev); return error; } +static int mxt_sysfs_init(struct mxt_data *data); +static void mxt_sysfs_remove(struct mxt_data *data); + static int mxt_configure_objects(struct mxt_data *data, const struct firmware *cfg); @@ -2141,16 +2145,24 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_sysfs_init(data); + if (error) + return error; + error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, &client->dev, GFP_KERNEL, data, mxt_config_cb); if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - return error; + goto err_free_sysfs; } return 0; + +err_free_sysfs: + mxt_sysfs_remove(data); + return error; } static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep) @@ -2803,6 +2815,7 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); } else { @@ -2909,16 +2922,25 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); + +static struct attribute *mxt_fw_attrs[] = { + &dev_attr_update_fw.attr, + NULL +}; + +static const struct attribute_group mxt_fw_attr_group = { + .attrs = mxt_fw_attrs, +}; + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); -static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, - &dev_attr_update_fw.attr, NULL }; @@ -2926,6 +2948,28 @@ static const struct attribute_group mxt_attr_group = { .attrs = mxt_attrs, }; +static int mxt_sysfs_init(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + if (error) { + dev_err(&client->dev, "Failure %d creating sysfs group\n", + error); + return error; + } + + return 0; +} + +static void mxt_sysfs_remove(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + + sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); +} + static void mxt_start(struct mxt_data *data) { switch (data->suspend_mode) { @@ -3112,19 +3156,14 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) if (error) return error; - error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + error = sysfs_create_group(&client->dev.kobj, &mxt_fw_attr_group); if (error) { - dev_err(&client->dev, "Failure %d creating sysfs group\n", + dev_err(&client->dev, "Failure %d creating fw sysfs group\n", error); - goto err_free_object; + return error; } return 0; - -err_free_object: - mxt_free_input_device(data); - mxt_free_object_table(data); - return error; } static int mxt_remove(struct i2c_client *client) @@ -3132,7 +3171,8 @@ static int mxt_remove(struct i2c_client *client) struct mxt_data *data = i2c_get_clientdata(client); disable_irq(data->irq); - sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); + sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); -- 2.17.1