Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp709927pxm; Fri, 25 Feb 2022 17:57:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyE7p01BS4rrBHBo7oos+75o9PtAUfNzCvKly/U3tDybyjnrHNSSrdQD6TarPxAXv59F5IE X-Received: by 2002:a63:3142:0:b0:373:a5f1:82bb with SMTP id x63-20020a633142000000b00373a5f182bbmr8583144pgx.163.1645840662064; Fri, 25 Feb 2022 17:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645840662; cv=none; d=google.com; s=arc-20160816; b=bX/ykSbqzaMug2EUOJJetauPUAdJ32U84SoB/GTK4RWSVETbDglIki13Y1SXmse82t iA1oBGBOLhSpWJs8avM9zpGuUbnUyISNq1zlEwv9dq7nUzYzpklTaun7piTNEtXOLYhy uKAayP5LmpzGPG/mpEP42eD2ix2+jpfzWqgX4GMF2XFrRdZJH1PiQY0svCnDMYsa3jpz EnxTO5ynagV69rQtVCJgjbX4aOjVTEUzOCgt1cgCLVNwZhiw+rF61AM6X67FRzEetUWm qsVMx731LlWFY3l3FrokPOA9DAO68t6Z01feWJv6oA/0I++LYcUCBADJb69ltHrj6LBv CP7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=vjStoIuqx4/+xKn8hhME8xw2P1U6/FgR67qcc7GF0Co=; b=1HGELGtFjm6VypLvMIyHLFF+Wk8U10qutHntIDzQidU8PKgD5u/vnWXjJNoWAY4xxn OuZzXDnoaxSWuh+CRQzlLtCwYNj029+7MCqlA8zE95r428U63Bp2I5n0VyEfBB+bx/Pj YD611yoh8MPuARAh5cW2bxXf1J3XR+r9DEmbubYOf3cI+o+uy7wFnrAuSocCMMfuUvdS xkb31VjMjHKt33zn7ndTJ3juMluO4ubFmps79si0SlJ+UJwHV2De0QH23l8FDyTk+DOs zgZ3IqO92V5vH0M1yV9GO/dCcQK/cJF1jTPmdy1A/RMMjgHcKu+HUl+M6QWCNMyztWwJ yNiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kBPHoRZ6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a15-20020a170902b58f00b0014fc82c77e8si3069739pls.441.2022.02.25.17.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 17:57:42 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kBPHoRZ6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E918628EBA7; Fri, 25 Feb 2022 17:41:05 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240908AbiBYNFg (ORCPT + 99 others); Fri, 25 Feb 2022 08:05:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240914AbiBYNFd (ORCPT ); Fri, 25 Feb 2022 08:05:33 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C25D1E5A5D; Fri, 25 Feb 2022 05:05:00 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id x15so4408265wrg.8; Fri, 25 Feb 2022 05:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=vjStoIuqx4/+xKn8hhME8xw2P1U6/FgR67qcc7GF0Co=; b=kBPHoRZ6GUxR3CkARd+hQ03jaD2d3oT3/qF94dp+4Z1PDLrGA4ZDYwes2ePSZbAMXi /wBslFDXVk3GGK/lyF53J88QCvbxcZHOjQlDVkrvwX0LWH1d59DHX64oCN/tHet0zNdp Iu5e/+57MxNk1herkrIzXxYdcKlqoikgVQDnZSsOxM0Cf+9k5TcLkNGmeI3U3PWHyIe6 +j5FdL8dw+JdsG158BpoFmN4LNx+C7K4Rnk8LCBs5bhx5TAqKAk53/jZmw87/CpYm7XF vSN17AlKfeZ12hqldO0NY3iz6m/nV0Aw8H5PmaZ6e6y5ls/Pxrz0PdQ1TCxEjmcyflr3 Z69A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vjStoIuqx4/+xKn8hhME8xw2P1U6/FgR67qcc7GF0Co=; b=wANwUl5Xee9DPecO80oB3vufxLUxz96X/TVYqU/USl3O4pQvnCUyGERDS4Xd8GkxRu d2Y9zVYs+DOlHcHmwwDfcULfWU/AfV452VP03DQzBmeKdvT5acM7DGoB7WZozxyvGZvv wooVkX5Jjjd+pvglANUsGa1r6dTFz/sConhJ801rRztGQhDCnFlK4h3dH4eZfrrC8Qy0 oRYVHDfTPSNDESgkH4F6kxVfRV6YOsyWbOJfbay95jXrvWfkMB2jMQiy382Ldz1L/bFw e8tcKUaknkKDUjGIpSaSnvwZa4Jd98tQDRQRbZpDxWRoFE4MSqCQPVZwuGqXi8uLTeHF s5qg== X-Gm-Message-State: AOAM530veb80IZOMS8zZLuqC8U6cX1TJculdymdMSZePrzkVvQDtWzSM ntsmiuRCdo/T57TrG0kJWBs= X-Received: by 2002:adf:fa8b:0:b0:1ee:d06f:ed0f with SMTP id h11-20020adffa8b000000b001eed06fed0fmr4658846wrr.535.1645794298905; Fri, 25 Feb 2022 05:04:58 -0800 (PST) Received: from localhost.localdomain ([64.64.123.58]) by smtp.gmail.com with ESMTPSA id d6-20020a5d4f86000000b001ea8119512bsm2148489wru.55.2022.02.25.05.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 05:04:58 -0800 (PST) From: Jia-Ju Bai To: hdegoede@redhat.com, markgross@kernel.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file() Date: Fri, 25 Feb 2022 05:04:48 -0800 Message-Id: <20220225130448.27063-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function device_create_file() in huawei_wmi_battery_add() can fail, so its return value should be checked. Fixes: 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds") Reported-by: TOTE Robot Signed-off-by: Jia-Ju Bai --- drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index a2d846c4a7ee..2ffd3840f3e8 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -470,10 +470,19 @@ static DEVICE_ATTR_RW(charge_control_thresholds); static int huawei_wmi_battery_add(struct power_supply *battery) { - device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold); - device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold); + int err = 0; + err = device_create_file(&battery->dev, + &dev_attr_charge_control_start_threshold); + if (err) + return err; + err = device_create_file(&battery->dev, + &dev_attr_charge_control_end_threshold); + if (err) { + device_remove_file(&battery->dev, + &dev_attr_charge_control_start_threshold); + } - return 0; + return err; } static int huawei_wmi_battery_remove(struct power_supply *battery) -- 2.17.1