Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp752150ybg; Thu, 19 Mar 2020 08:09:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vscr3pPSpWvnLk2rxE73SUUeoTvBehCofakVH/xVansPrxR9cLU+1GEdPwDIUj8p4qumI32 X-Received: by 2002:a05:6830:19ce:: with SMTP id p14mr2613230otp.362.1584630553178; Thu, 19 Mar 2020 08:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584630553; cv=none; d=google.com; s=arc-20160816; b=T6lRM18vFkWGNl5kccyclNCgyfrn9ufZHqDDRKUrUuPbhwmGFUyfwyMrUumZfIdbev ZQI9V9kiMrnWZKh2+h+6YEopewHA557jQVp4/i5ZOrW28wBaRlJ8GOIWU5ypl3GdT+z0 rZEStLPVwWp01Xa3dvO6lzQ5wrj8AIp0M4IqiFx+4nbH3DKxaIb1YtZx5HE5OWT4cHDR WbKR83pcFTCPk0eRNmdbGIQU4JYOxGaR7X7D5oMez26Oizbxp7AlUb2DQKvX6xVEUwJK KC6+jui8pzTOweYkqz5k1FOuONoOV1q8R7rE4Fs//KU/5N0/XeKjoEZpr3dD00Z5GG0k sVDQ== 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=6KI/N4Osb55eI/AoHdHB02/R8j+TEEY6xrXA+oBt7DM=; b=yTAm6gkov19ntNc2tWkyB6HQMEjV5uDF7Hnvp0qIV67FzVPq/swdsfjOCAb25MDXkk gvmpkfXWG17GpalN/O2wpoUWrHg4ioYMIp3QMZnnOUieiPBVhU6UDyCEMqqnXNMQ2bKo KPVP6kn4FvSAuyEGHtFtZAQxuUM+wMxfawxR+IbJ6uW2fCvEAHkODY+fFAlUHJ+fpmP5 7nlnVl7xL3fMoYauyiZh3h4rlfJWtcmpjI5dvdE2GrwpQYFF7U3svA2zc8NMZ6cx7xnS oV6YJRUrdGQK+EJwxB1Dv9mwon96zQxJFu/3P6J1iZFV3cP/GngoCnEt17kyJsBBYVti W3ug== 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 g206si1147555oib.17.2020.03.19.08.08.41; Thu, 19 Mar 2020 08:09:13 -0700 (PDT) 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 S1728453AbgCSPHk (ORCPT + 99 others); Thu, 19 Mar 2020 11:07:40 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5879 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728308AbgCSPHi (ORCPT ); Thu, 19 Mar 2020 11:07:38 -0400 IronPort-SDR: wRSxf5HblxQ9NwYT/GBjzJCJSrEAZwQ4Iowek5/+9BCDrc2NvG2QbPk8z1QxzoXLDHdUSSWRnt dMhfHe3raYTp6xhHOkeOb59vcD7W4fE+Xgbm7JeNExuwEl5kV3qTNnizJDnMrUzyuEm5me7PIa DkRGXNAmEHrPN7gpzaIxkenK84ij7+L407lRod24ryhFNoPjqKAsQPRT9ojO/SoqivZJgTxYHe z4sJzbZykPn63FzMJPKbGaPrqe/xwRaSTW7CBdRmvlCYbaYbAvyrh6CW0bpOPee0rvPKzVwegc /t0= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926665" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:30 -0800 IronPort-SDR: NX7S6w1EKKo/U3RM91oBUeld1qZA4Yij+7/9LBJlrVgADf2aaDkglnKrMJUcfY8tFeTqqoupC6 EK6GtAjnKz1u1CxqDDFENYlQMeozI721oQkkkN7pqd33N4ava0QCCf5fsaGum6E/xkrQKb94DM y3d5FQBl9Pft6URIM2lk1RPfzizNbTFhjyjr5psVBo3RWQlg6SSoaHhDsTqpJyrKcq1i58K1mG Pdz4kp/8eQUwCDKBh5h2zxv6UyGHjXehxry5csji+2a8rkTXzucNhp6JHycQiWvdyd6EaW9qKN g6E= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 02/52] Input: atmel_mxt_ts - rework sysfs init/remove Date: Thu, 19 Mar 2020 07:59:26 -0700 Message-ID: <20200319150016.61398-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 replace S_IWUSR with 0200] 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 a2189739e30f..49bdf5cf3a0d 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, 0200, 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