From patchwork Fri Jun 22 02:27:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10481047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 796C160383 for ; Fri, 22 Jun 2018 02:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66A3B290AB for ; Fri, 22 Jun 2018 02:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5741B290B2; Fri, 22 Jun 2018 02:28:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF7EE290AB for ; Fri, 22 Jun 2018 02:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934277AbeFVC1s (ORCPT ); Thu, 21 Jun 2018 22:27:48 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34410 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934264AbeFVC1V (ORCPT ); Thu, 21 Jun 2018 22:27:21 -0400 Received: by mail-pl0-f68.google.com with SMTP id g20-v6so2693448plq.1 for ; Thu, 21 Jun 2018 19:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WMyAjY1vl2H1AbFT10CqHLgdfFvChhGoJud0E6JUeAc=; b=hHyVQiTOtGPjLtfPkGzxly7aekm3CTGrN5Pc06IBZWSkEzMOAKB7x0DQNk4Pi5Fl43 weitcItMq7yL/Olt7IDnBOQq7MgwfAx5yCOW+r0Wmq91LLpXxUPCPb1atxWXSQukK0Fu pUF3PZFmBXh9E9ngMQgwJgF/JyxJ2Uvus2sWY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WMyAjY1vl2H1AbFT10CqHLgdfFvChhGoJud0E6JUeAc=; b=rmOuY2u2ejQ2KgmeEEcj5/EaDJDeYFXkjDQquv5+Ev6g+uWHXArlnsUSkbojLfCUFI pEb25GFAcOR0ZsaKdlktz7RviFsII8ZKRAeQ5X5vE9BV2pI22DZn3Lm8UK4PdmcLuqnG 1SPbgO4udhCOqlZ07rudtM3IhDV3We7eqwXRq70+aZ2X+H6qTJd9FY8/grx9nOeLOVmt hqn9JG41Z5kOadISTvEiPk1WLrOJMEgSA/YTJCJQiOcn7uK5tOAom7ASA+yUp8RtyLEA PCnK5hiUs8GytrTDV/1CFDpox93p6wrnARYLJfRNjJnR7cwcyIVkdUt9yfX4EJ1d1OWI 51kg== X-Gm-Message-State: APt69E3cx/IK/4o231K8KPYBJr9k02fRhfU3hOsIh7MztoXnoHofr4/Q ob7/j4/9HAcgm/RUVpYsI0MdQw== X-Google-Smtp-Source: ADUXVKKAP1BAmMSauWapuijbIOrafQCbvjqgOHt69yDShBBy6pVVEqLOhS/1vdVtZIHYGg1T79HD0w== X-Received: by 2002:a17:902:b110:: with SMTP id q16-v6mr31121205plr.286.1529634441268; Thu, 21 Jun 2018 19:27:21 -0700 (PDT) Received: from swboyd.mtv.corp.google.com ([2620:0:1000:1511:d30e:62c6:f82c:ff40]) by smtp.gmail.com with ESMTPSA id b74-v6sm13889045pfl.138.2018.06.21.19.27.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jun 2018 19:27:20 -0700 (PDT) From: Stephen Boyd To: Jiri Kosina Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Benjamin Tissoires , Hans de Goede , Andy Shevchenko , Dmitry Torokhov , Doug Anderson Subject: [PATCH v3 1/2] HID: i2c-hid: Use devm to allocate i2c_hid struct Date: Thu, 21 Jun 2018 19:27:16 -0700 Message-Id: <20180622022717.134300-2-swboyd@chromium.org> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: <20180622022717.134300-1-swboyd@chromium.org> References: <20180622022717.134300-1-swboyd@chromium.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm here to save some lines and prepare for bulk regulator usage in this driver. Otherwise, when we devm bulk get regulators we'll free the containing i2c_hid structure and try to put regulator pointers from freed memory. Cc: Benjamin Tissoires Cc: Hans de Goede Cc: Andy Shevchenko Cc: Dmitry Torokhov Cc: Doug Anderson Signed-off-by: Stephen Boyd Acked-by: Benjamin Tissoires --- drivers/hid/i2c-hid/i2c-hid.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index c1652bb7bd15..c7d6738dc524 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -1002,18 +1002,18 @@ static int i2c_hid_probe(struct i2c_client *client, return client->irq; } - ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); + ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); if (!ihid) return -ENOMEM; if (client->dev.of_node) { ret = i2c_hid_of_probe(client, &ihid->pdata); if (ret) - goto err; + return ret; } else if (!platform_data) { ret = i2c_hid_acpi_pdata(client, &ihid->pdata); if (ret) - goto err; + return ret; } else { ihid->pdata = *platform_data; } @@ -1126,7 +1126,6 @@ static int i2c_hid_probe(struct i2c_client *client, err: i2c_hid_free_buffers(ihid); - kfree(ihid); return ret; } @@ -1150,8 +1149,6 @@ static int i2c_hid_remove(struct i2c_client *client) regulator_disable(ihid->pdata.supply); - kfree(ihid); - return 0; }