From patchwork Wed Jan 13 18:21:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12017515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4B2BC433E6 for ; Wed, 13 Jan 2021 18:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E1022343E for ; Wed, 13 Jan 2021 18:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728146AbhAMSWQ (ORCPT ); Wed, 13 Jan 2021 13:22:16 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:38090 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728111AbhAMSWQ (ORCPT ); Wed, 13 Jan 2021 13:22:16 -0500 Date: Wed, 13 Jan 2021 18:21:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1610562092; bh=qwOcPHx8CghzjRJLnaroNCyPJmkDiZo+MrHBCOEZaww=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=m7CSAdY13oqDJpXZaPDQIvDbVskdY+kGAl//yhjyyuK83J1Pnq5iszqTsrTdjxKTT JVE8Al0+U1tJgJotKBGiqUNm22wBxmoaFEd0Qeunt9V8G0EjrzV5BSnIDr9asRMhlz vbbXYG//UXrMscZQ+HY0VjeoUdmfPoVghh3FK5Vg= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v2 10/24] platform/x86: ideapad-laptop: misc. device attribute changes Message-ID: <20210113182016.166049-11-pobrn@protonmail.com> In-Reply-To: <20210113182016.166049-1-pobrn@protonmail.com> References: <20210113182016.166049-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Do not handle zero length buffer separately. Use kstrtouint() instead of sscanf(). Signed-off-by: Barnabás Pőcze Reviewed-by: Hans de Goede diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 677d4e10352e..cba3d9419f52 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -365,13 +365,13 @@ static ssize_t store_ideapad_cam(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; + int ret; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; + ret = kstrtouint(buf, 0, &state); + if (ret) + return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); if (ret) return ret; @@ -398,14 +398,14 @@ static ssize_t store_ideapad_fan(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ret, state; + int ret; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned int state; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; - if (state < 0 || state > 4 || state == 3) + ret = kstrtouint(buf, 0, &state); + if (ret) + return ret; + if (state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); if (ret)