Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9627529imu; Wed, 5 Dec 2018 07:50:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/XVsFv8xmtdWGTPVTjdyGQDg0k2iGM244FCWM6d7vWoyMubaJiHtl4kCl5JdAEQ6o3/BYkv X-Received: by 2002:a65:5a4c:: with SMTP id z12mr20825431pgs.188.1544025010279; Wed, 05 Dec 2018 07:50:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544025010; cv=none; d=google.com; s=arc-20160816; b=tsyfoSbCl8797hMo32ET5DC7PFQI5/a6hL1aqK/vLs4ZGdwyHfiUJGP5o7n0yWqjrS psrw2hOK4FQ2bxTtIPrR4nyfqPBtujwjEmgaMIjT2WLNy7zbBXnrJGirJ3I4g7swSXzB AFXxhoeHhtGD5u2rFfQ0jnsCuM2vWJ1gTVUCxYqdz+aCWo0IIiXzt1W/p2RKJWfPthep a0Sh9g/lhNSpnXKKQuSfXZildPQlgO/6QBqGtAAUxM2VJmNZ3c2lRNRsbpRIC6Eh67Hn W/rpCowUfxLt03QPHq3C6clEWBMk8MYP/6Y44TY51UY1w/sFGtpNC1sP4B6cqBLVz88J xeDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ffKmnpXVEGqvKdWMlz9/DjQRtkJ60DTmwDe4HXvNTn8=; b=SLI8mqzKxkqGd/joqbTHLnsKgNzqBwVy7lFlv7dZxw8LyErFcnLoSzntS6diRzBo30 uzA3SYFSazwSDARcKTFAQjHm3RF5O4xWSfbV6CjqNJ67p30sdwuo1f7L94vJ7RlIC3Ue q7m6F4eCZEGTFLE0NSm/LPoQWasuBZgMgbNnIPxiqaL0eJ7nh0CWMom7axEtEwBpGiTm SPL/MckovrWOhgwS0lN3bSv7ZEjOzad5HL8RzPJ8Laojoa5I2f9C2M79H0H5YJs3TYPG KU1vONGDEr26x8PAlH/fLPXZ9d0NY4R4et5wEt5qWnA6NylRQkO/gFZ9LhTOQTNklfbq xxFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gUOxfkvs; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y123si20522342pfy.18.2018.12.05.07.49.55; Wed, 05 Dec 2018 07:50:10 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gUOxfkvs; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728149AbeLEPs7 (ORCPT + 99 others); Wed, 5 Dec 2018 10:48:59 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:47029 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbeLEPs6 (ORCPT ); Wed, 5 Dec 2018 10:48:58 -0500 Received: by mail-lf1-f66.google.com with SMTP id f23so15061164lfc.13; Wed, 05 Dec 2018 07:48:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ffKmnpXVEGqvKdWMlz9/DjQRtkJ60DTmwDe4HXvNTn8=; b=gUOxfkvsJ+4crGEsAQFnrfC7IktC3ABIKy49VQhgvwHrOd7VSECyn6OdaqtWRgRr4d eM+rPmHVC0dfw+15LmKFB9Iop00sA6qNMRVxssuaAC8uaeeKhLH/6IlcdQiBIEERFZbc Mu4FSDCJAmDfmaSRCQ2JcWygspwB3Xec9lXifUKYVpGzmXMViFebHirJXLGt6MRPSGME V+nD+4AiYU/oZSf09gFhes+rEyV0eDvnMCD+N1T5Hv2dhLKMjs4eurE35BRBseOomraC Qz8i4oBUovpwUF034RON3UZmt6ulx1QQNndNUmluicobmvkUWBAKP9aSbTslz19NdnHX XQPg== 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:mime-version:content-transfer-encoding; bh=ffKmnpXVEGqvKdWMlz9/DjQRtkJ60DTmwDe4HXvNTn8=; b=i5JHzborwAcnFWgOm307u6nb4bhunBIbFPaL2AsrBjnaXtSEJO1OeJcQFvdu/J5zuD bbmPNKWlfKvBSoJefxMNJQp5M+5xrDqu8uS+e0u2+BIrk2+xIHKp/fy+kRmoBEs6nEaP XrYNyNs6vL+JWgd3VzxfyhiDk9ZxKRO9NKR8DdnivLAxMKVWxeGRKjHpdTl+6h5LVIxW 5CDkxK4LD4Hza6V207b53yIV5p0lP8ZpxNZCH29BG0iil5WM1K8l/si+FdnfVxh5xWsF Q4bU+7idZSTyji+waoyRc/mI1r/9vavgIbQgVE81cbjb/a8NFDafN5m54kDezpn0smIt eWMw== X-Gm-Message-State: AA+aEWZNMZ7czgwptQYuRAvlUV0TYj0O/+tW/22vvI6+bwquMxy/sdiF AjX1rEl1kc5l8xrQkVK/P0k= X-Received: by 2002:a19:f813:: with SMTP id a19mr14088331lff.67.1544024934173; Wed, 05 Dec 2018 07:48:54 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:41e8:260c:942a:b736]) by smtp.googlemail.com with ESMTPSA id t18sm3592517lft.93.2018.12.05.07.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 07:48:53 -0800 (PST) From: =?UTF-8?q?Pawe=C5=82=20Chmiel?= To: mchehab@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: hverkuil@xs4all.nl, fischerdouglasc@gmail.com, keescook@chromium.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, =?UTF-8?q?Pawe=C5=82=20Chmiel?= Subject: [PATCH 3/5] si470x-i2c: Use managed resource helpers Date: Wed, 5 Dec 2018 16:47:48 +0100 Message-Id: <20181205154750.17996-4-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181205154750.17996-1-pawel.mikolaj.chmiel@gmail.com> References: <20181205154750.17996-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify cleanup of failures by using managed resource helpers Signed-off-by: Paweł Chmiel --- drivers/media/radio/si470x/radio-si470x-i2c.c | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c index 250828ddb5fa..a7ac09c55188 100644 --- a/drivers/media/radio/si470x/radio-si470x-i2c.c +++ b/drivers/media/radio/si470x/radio-si470x-i2c.c @@ -350,7 +350,7 @@ static int si470x_i2c_probe(struct i2c_client *client, unsigned char version_warning = 0; /* private data allocation and initialization */ - radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL); + radio = devm_kzalloc(&client->dev, sizeof(*radio), GFP_KERNEL); if (!radio) { retval = -ENOMEM; goto err_initial; @@ -370,7 +370,7 @@ static int si470x_i2c_probe(struct i2c_client *client, retval = v4l2_device_register(&client->dev, &radio->v4l2_dev); if (retval < 0) { dev_err(&client->dev, "couldn't register v4l2_device\n"); - goto err_radio; + goto err_initial; } v4l2_ctrl_handler_init(&radio->hdl, 2); @@ -396,14 +396,14 @@ static int si470x_i2c_probe(struct i2c_client *client, radio->registers[POWERCFG] = POWERCFG_ENABLE; if (si470x_set_register(radio, POWERCFG) < 0) { retval = -EIO; - goto err_ctrl; + goto err_all; } msleep(110); /* get device and chip versions */ if (si470x_get_all_registers(radio) < 0) { retval = -EIO; - goto err_ctrl; + goto err_all; } dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n", radio->registers[DEVICEID], radio->registers[SI_CHIPID]); @@ -430,10 +430,10 @@ static int si470x_i2c_probe(struct i2c_client *client, /* rds buffer allocation */ radio->buf_size = rds_buf * 3; - radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL); + radio->buffer = devm_kmalloc(&client->dev, radio->buf_size, GFP_KERNEL); if (!radio->buffer) { retval = -EIO; - goto err_ctrl; + goto err_all; } /* rds buffer configuration */ @@ -441,12 +441,13 @@ static int si470x_i2c_probe(struct i2c_client *client, radio->rd_index = 0; init_waitqueue_head(&radio->read_queue); - retval = request_threaded_irq(client->irq, NULL, si470x_i2c_interrupt, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME, - radio); + retval = devm_request_threaded_irq(&client->dev, client->irq, NULL, + si470x_i2c_interrupt, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + DRIVER_NAME, radio); if (retval) { dev_err(&client->dev, "Failed to register interrupt\n"); - goto err_rds; + goto err_all; } /* register video device */ @@ -460,15 +461,9 @@ static int si470x_i2c_probe(struct i2c_client *client, return 0; err_all: - free_irq(client->irq, radio); -err_rds: - kfree(radio->buffer); -err_ctrl: v4l2_ctrl_handler_free(&radio->hdl); err_dev: v4l2_device_unregister(&radio->v4l2_dev); -err_radio: - kfree(radio); err_initial: return retval; } @@ -481,9 +476,7 @@ static int si470x_i2c_remove(struct i2c_client *client) { struct si470x_device *radio = i2c_get_clientdata(client); - free_irq(client->irq, radio); video_unregister_device(&radio->videodev); - kfree(radio); return 0; } -- 2.17.1