From patchwork Fri Aug 17 04:49:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 10780 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3EE3E23E28 for ; Fri, 17 Aug 2012 04:51:01 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id E4A57A18219 for ; Fri, 17 Aug 2012 04:51:00 +0000 (UTC) Received: by yhpp61 with SMTP id p61so3871355yhp.11 for ; Thu, 16 Aug 2012 21:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=WAD3JYPG+2uNYV+WptNlCmo2zIt9nAfKt8a9CdrYpwI=; b=ZvSmOIFsU5WeRXd8qgZK52Z+wupIC3vX3kVe/NTlh1ygfuTAw2kWwD3xDMsadEy/43 KZXF5idV+72Sq9Dvh4fYQdkpGShLomoo+bxkHkkr9jE7z56dkbuOCT6JhuB9WpKShIZq oqSKXQLdKnNjZn7jijk9SOCKKswGv/D/sm/ShzBk5tkwUNj0yf1MAdC1FNTskuyS5snF AaZimLu3MDxgHAYS59Cl1wDzSHpuoDat0oNt61bUh9Q3wHf/CtUxTGPWT4X1w8FguB3i mVxPprxD82Cgf8+E2IOfMvtfkzYp+yjphrM/7AM2wbQXFL9j8x3iWmMHBMYBrF+B8i3Q zTqg== Received: by 10.50.6.229 with SMTP id e5mr580324iga.9.1345179060166; Thu, 16 Aug 2012 21:51:00 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.200 with SMTP id ew8csp170462igc; Thu, 16 Aug 2012 21:50:59 -0700 (PDT) Received: by 10.68.203.200 with SMTP id ks8mr8453050pbc.142.1345179059563; Thu, 16 Aug 2012 21:50:59 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id tf5si11272854pbc.336.2012.08.16.21.50.59 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Aug 2012 21:50:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by pbcmd12 with SMTP id md12so3089120pbc.37 for ; Thu, 16 Aug 2012 21:50:59 -0700 (PDT) Received: by 10.68.234.7 with SMTP id ua7mr8627949pbc.91.1345179056082; Thu, 16 Aug 2012 21:50:56 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id nd2sm4107053pbc.7.2012.08.16.21.50.53 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Aug 2012 21:50:55 -0700 (PDT) From: Sachin Kamat To: linux-media@vger.kernel.org Cc: mchehab@infradead.org, sakari.ailus@iki.fi, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH v2] smiapp: Use devm_* functions in smiapp-core.c file Date: Fri, 17 Aug 2012 10:19:02 +0530 Message-Id: <1345178942-6771-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQmjJGsCX6SglUEuoykGXfqm8OzMZefiFp8UunyKwHcaApKPjxusJJqQCS6cTRmssWqW5CLe devm_* functions are device managed functions and make code a bit smaller and cleaner. Signed-off-by: Sachin Kamat --- Changes since v1: Used devm_kzalloc for sensor->nvm. Used devm_clk_get and devm_regulator_get functions. This patch is based on Mauro's re-organized tree (media_tree staging/for_v3.7) and is compile tested. --- drivers/media/i2c/smiapp/smiapp-core.c | 47 +++++++------------------------ 1 files changed, 11 insertions(+), 36 deletions(-) diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c index 1cf914d..4f1c8d6 100644 --- a/drivers/media/i2c/smiapp/smiapp-core.c +++ b/drivers/media/i2c/smiapp/smiapp-core.c @@ -2355,20 +2355,19 @@ static int smiapp_registered(struct v4l2_subdev *subdev) unsigned int i; int rval; - sensor->vana = regulator_get(&client->dev, "VANA"); + sensor->vana = devm_regulator_get(&client->dev, "VANA"); if (IS_ERR(sensor->vana)) { dev_err(&client->dev, "could not get regulator for vana\n"); return -ENODEV; } if (!sensor->platform_data->set_xclk) { - sensor->ext_clk = clk_get(&client->dev, - sensor->platform_data->ext_clk_name); + sensor->ext_clk = devm_clk_get(&client->dev, + sensor->platform_data->ext_clk_name); if (IS_ERR(sensor->ext_clk)) { dev_err(&client->dev, "could not get clock %s\n", sensor->platform_data->ext_clk_name); - rval = -ENODEV; - goto out_clk_get; + return -ENODEV; } rval = clk_set_rate(sensor->ext_clk, @@ -2378,8 +2377,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev) "unable to set clock %s freq to %u\n", sensor->platform_data->ext_clk_name, sensor->platform_data->ext_clk); - rval = -ENODEV; - goto out_clk_set_rate; + return -ENODEV; } } @@ -2389,8 +2387,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev) dev_err(&client->dev, "unable to acquire reset gpio %d\n", sensor->platform_data->xshutdown); - rval = -ENODEV; - goto out_clk_set_rate; + return -ENODEV; } } @@ -2470,8 +2467,8 @@ static int smiapp_registered(struct v4l2_subdev *subdev) * when it is first requested by userspace. */ if (sensor->minfo.smiapp_version && sensor->platform_data->nvm_size) { - sensor->nvm = kzalloc(sensor->platform_data->nvm_size, - GFP_KERNEL); + sensor->nvm = devm_kzalloc(&client->dev, + sensor->platform_data->nvm_size, GFP_KERNEL); if (sensor->nvm == NULL) { dev_err(&client->dev, "nvm buf allocation failed\n"); rval = -ENOMEM; @@ -2637,21 +2634,12 @@ out_nvm_release: device_remove_file(&client->dev, &dev_attr_nvm); out_power_off: - kfree(sensor->nvm); - sensor->nvm = NULL; smiapp_power_off(sensor); out_smiapp_power_on: if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) gpio_free(sensor->platform_data->xshutdown); -out_clk_set_rate: - clk_put(sensor->ext_clk); - sensor->ext_clk = NULL; - -out_clk_get: - regulator_put(sensor->vana); - sensor->vana = NULL; return rval; } @@ -2801,12 +2789,11 @@ static int smiapp_probe(struct i2c_client *client, const struct i2c_device_id *devid) { struct smiapp_sensor *sensor; - int rval; if (client->dev.platform_data == NULL) return -ENODEV; - sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); + sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); if (sensor == NULL) return -ENOMEM; @@ -2821,12 +2808,8 @@ static int smiapp_probe(struct i2c_client *client, sensor->src->sensor = sensor; sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE; - rval = media_entity_init(&sensor->src->sd.entity, 2, + return media_entity_init(&sensor->src->sd.entity, 2, sensor->src->pads, 0); - if (rval < 0) - kfree(sensor); - - return rval; } static int __exit smiapp_remove(struct i2c_client *client) @@ -2845,10 +2828,8 @@ static int __exit smiapp_remove(struct i2c_client *client) sensor->power_count = 0; } - if (sensor->nvm) { + if (sensor->nvm) device_remove_file(&client->dev, &dev_attr_nvm); - kfree(sensor->nvm); - } for (i = 0; i < sensor->ssds_used; i++) { media_entity_cleanup(&sensor->ssds[i].sd.entity); @@ -2857,12 +2838,6 @@ static int __exit smiapp_remove(struct i2c_client *client) smiapp_free_controls(sensor); if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) gpio_free(sensor->platform_data->xshutdown); - if (sensor->ext_clk) - clk_put(sensor->ext_clk); - if (sensor->vana) - regulator_put(sensor->vana); - - kfree(sensor); return 0; }