From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67F6AEB64D0 for ; Tue, 13 Jun 2023 16:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233897AbjFMQkd (ORCPT ); Tue, 13 Jun 2023 12:40:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbjFMQkG (ORCPT ); Tue, 13 Jun 2023 12:40:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0F13198B; Tue, 13 Jun 2023 09:40:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 565E763792; Tue, 13 Jun 2023 16:40:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EEA8C433D9; Tue, 13 Jun 2023 16:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686674404; bh=OkeHnH/TAQmovfwxd3UYG175EWl8VQgpXW7nfWPlfQc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PZ8A6xw3FtPAEpEP/h7HaFK8Mz0b77IlSmbpMrh7O46mIvicDAufHsTKMr0q/Z1Ei 8ABG7o0GoWpe10KxyVfSShuQhYaZnzMOClJQZr2f+S4SV7ovZhA9FrA6KbjWzot4uz 44yb2L/gaEZyRvCRV816lysX0XAEIZrMTw+rdyvEMVIVLzTfFVZLFaz95rVSxeP6Yw Ys5hEtlFCZOvU91wD7c+/YljzqLo2WydeN3vGLzHO2kzQLjOZhSqfCXR42tT3z98ZP xfSQppuf5YTIdIS23LOi78msw6EIpD/qeiELcAPsM8eNwVhtStRL7ViVoHMpQQV+B2 ILAVXHHaQ3RAQ== Received: by pali.im (Postfix) id 92D847FD; Tue, 13 Jun 2023 18:40:01 +0200 (CEST) Date: Tue, 13 Jun 2023 18:40:01 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Michal Wilczynski Cc: linux-acpi@vger.kernel.org, rafael@kernel.org, andriy.shevchenko@intel.com, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, fengguang.wu@intel.com, dvhart@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: Re: [PATCH v2] platform/x86/dell/dell-rbtn: Fix resources leaking on error path Message-ID: <20230613164001.5vdk4pajbrwgdam4@pali> References: <20230613084310.2775896-1-michal.wilczynski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230613084310.2775896-1-michal.wilczynski@intel.com> User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 13 June 2023 11:43:10 Michal Wilczynski wrote: > Currently rbtn_add() in case of failure is leaking resources. Fix this > by adding a proper rollback. Move devm_kzalloc() before rbtn_acquire(), > so it doesn't require rollback in case of failure. While at it, remove > unnecessary assignment of NULL to device->driver_data and unnecessary > whitespace, plus add a break for the default case in a switch. > > Suggested-by: Ilpo Järvinen > Fixes: 817a5cdb40c8 ("dell-rbtn: Dell Airplane Mode Switch driver") > Signed-off-by: Michal Wilczynski > Reviewed-by: Andy Shevchenko > Acked-by: Rafael J. Wysocki Looks good, Reviewed-by: Pali Rohár > --- > v2: > - move devm_kzalloc before rbtn_acquire as suggested > > drivers/platform/x86/dell/dell-rbtn.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/platform/x86/dell/dell-rbtn.c b/drivers/platform/x86/dell/dell-rbtn.c > index aa0e6c907494..c8fcb537fd65 100644 > --- a/drivers/platform/x86/dell/dell-rbtn.c > +++ b/drivers/platform/x86/dell/dell-rbtn.c > @@ -395,16 +395,16 @@ static int rbtn_add(struct acpi_device *device) > return -EINVAL; > } > > + rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL); > + if (!rbtn_data) > + return -ENOMEM; > + > ret = rbtn_acquire(device, true); > if (ret < 0) { > dev_err(&device->dev, "Cannot enable device\n"); > return ret; > } > > - rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL); > - if (!rbtn_data) > - return -ENOMEM; > - > rbtn_data->type = type; > device->driver_data = rbtn_data; > > @@ -420,10 +420,12 @@ static int rbtn_add(struct acpi_device *device) > break; > default: > ret = -EINVAL; > + break; > } > + if (ret) > + rbtn_acquire(device, false); > > return ret; > - > } > > static void rbtn_remove(struct acpi_device *device) > @@ -442,7 +444,6 @@ static void rbtn_remove(struct acpi_device *device) > } > > rbtn_acquire(device, false); > - device->driver_data = NULL; > } > > static void rbtn_notify(struct acpi_device *device, u32 event) > -- > 2.41.0 >