lkml.org 
[lkml]   [2000]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] sd.c: handling resource allocation failure
Andries Brouwer wrote:
>
> On Wed, Aug 23, 2000 at 07:15:40PM +0100, Tigran Aivazian wrote:
>
> > > rscsi_disks = (Scsi_Disk *)
> > > kmalloc(sd_template.dev_max * sizeof(Scsi_Disk), GFP_ATOMIC);
> >
> > no need to cast return from kmalloc, it returns (void *) and typecasts are
> > tiresome to eyes (human eyes, i.e.).
>
> Hmm. I am not sure I agree.
>
> Usually type casts are bad, because they tell the compiler
> not to check, and therefore may hide problems.
>
> In a case like this, where a (void *) is returned, casting
> to the proper pointer type is meaningful: it allows the compiler
> to check the type, and the human eye to check that the right
> amount of memory is allocated.
>
> If you just write
> foo = kmalloc(n * sizeof(some_type), GFP_x);
> then neither the compiler nor the human eye can check
> easily that things are right, i.e. that foo really is
> a (some_type *).
>

Then you need to propose:
#define Kmalloc(type, n, flag) (type *)kmalloc(sizeof(type)*n, flag)

--
Abramo Bagnara mailto:abramo@alsa-project.org

Opera Unica
Via Emilia Interna, 140 Phone: +39.0546.656023
48014 Castel Bolognese (RA) - Italy Fax: +39.0546.656023

ALSA project is http://www.alsa-project.org
sponsored by SuSE Linux http://www.suse.com

It sounds good!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:38    [W:0.051 / U:2.156 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site