From patchwork Mon Aug 20 18:32:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Goode X-Patchwork-Id: 1350571 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 68035DFB6E for ; Mon, 20 Aug 2012 18:29:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752085Ab2HTS3T (ORCPT ); Mon, 20 Aug 2012 14:29:19 -0400 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]:58051 "EHLO mail-lpp01m010-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752778Ab2HTS3O (ORCPT ); Mon, 20 Aug 2012 14:29:14 -0400 Received: by lagy9 with SMTP id y9so3450656lag.19 for ; Mon, 20 Aug 2012 11:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=OjT6aX/INYCy2pKLKlflJI+8CiHbYQdR7K/MxhMS2WI=; b=fwtmaQ5BluGmp8uXXzyaIh1HWMEXO4aZV8F0NP0Q6VIyn17HzVw3LTvSgivmU2eIgv UvyVbmCPUqlZ8UTEfRZ+DWrTIZ5hgWzyVNet4u//Mwd+nHn6nWUYXbxTjdDDTJkIXRd1 z2QNRxjKH9zU9vH7ljkT00ylMh68fnvQWxG6Mcr/EtHve7ZnUN1h4K8rR2RxmiSPtPIq B0NgrsQe1hEh2jnGJOpU6xlAH1KA+goG9I0YyINFqB3SSPTX3z+oCmE/7CsvX4ZAh2Y5 en+R3xKWsINsS9zkDBnv2dfsRel+0exfZKvXF3gyqSr5SpD6PuIq/6giiYEjHbDzBoHF R8GQ== Received: by 10.112.46.135 with SMTP id v7mr6599186lbm.3.1345487352629; Mon, 20 Aug 2012 11:29:12 -0700 (PDT) Received: from localhost.localdomain (213-66-219-246-no119.business.telia.com. [213.66.219.246]) by mx.google.com with ESMTPS id u10sm1417513lbf.11.2012.08.20.11.29.10 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Aug 2012 11:29:11 -0700 (PDT) From: Emil Goode To: FlorianSchandinat@gmx.de Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Emil Goode Subject: [PATCH] video: hpfb: Fix error handling Date: Mon, 20 Aug 2012 20:32:25 +0200 Message-Id: <1345487545-9590-1-git-send-email-emilgoode@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org This patch solves problems with the error handling by introducing labels for proper error paths and it also frees resources that where missed. Signed-off-by: Emil Goode --- drivers/video/hpfb.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/video/hpfb.c b/drivers/video/hpfb.c index ebf8495..7324865 100644 --- a/drivers/video/hpfb.c +++ b/drivers/video/hpfb.c @@ -210,6 +210,7 @@ static int __devinit hpfb_init_one(unsigned long phys_base, unsigned long virt_base) { unsigned long fboff, fb_width, fb_height, fb_start; + int ret; fb_regs = virt_base; fboff = (in_8(fb_regs + HPFB_FBOMSB) << 8) | in_8(fb_regs + HPFB_FBOLSB); @@ -290,19 +291,29 @@ static int __devinit hpfb_init_one(unsigned long phys_base, fb_info.var = hpfb_defined; fb_info.screen_base = (char *)fb_start; - fb_alloc_cmap(&fb_info.cmap, 1 << hpfb_defined.bits_per_pixel, 0); + ret = fb_alloc_cmap(&fb_info.cmap, 1 << hpfb_defined.bits_per_pixel, 0); + if (ret < 0) + goto unmap_screen_base; - if (register_framebuffer(&fb_info) < 0) { - fb_dealloc_cmap(&fb_info.cmap); - iounmap(fb_info.screen_base); - fb_info.screen_base = NULL; - return 1; - } + ret = register_framebuffer(&fb_info); + if (ret < 0) + goto dealloc_cmap; printk(KERN_INFO "fb%d: %s frame buffer device\n", fb_info.node, fb_info.fix.id); return 0; + +dealloc_cmap: + fb_dealloc_cmap(&fb_info.cmap); + +unmap_screen_base: + if (fb_info.screen_base) { + iounmap(fb_info.screen_base); + fb_info.screen_base = NULL; + } + + return ret; } /* @@ -345,6 +356,9 @@ static void __devexit hpfb_remove_one(struct dio_dev *d) if (d->scode >= DIOII_SCBASE) iounmap((void *)fb_regs); release_mem_region(d->resource.start, resource_size(&d->resource)); + fb_dealloc_cmap(&fb_info.cmap); + if (fb_info.screen_base) + iounmap(fb_info.screen_base); } static struct dio_device_id hpfb_dio_tbl[] = {