In function () assignment makes pointer from integer without a cast

Dear Boardsters,

The log file gives me:
 In function ‘memFileAlloc’ assignment makes pointer from integer without a cast 


When compiling the drivers for the Matrox card in the DL580. The offending code is:


STACK_LINKAGE MEMHANDLE memFileAlloc(
    UINT32 dwSize,
    const char* pszFileName,
    int iLine)
{
    void* pvChunk;
  #if MEMORY_STATS
    pvChunk = ClientMemStatsAlloc(dwSize + sizeof[UINT32], pszFileName, iLine);
  #else
    pvChunk = ClientMemAlloc(dwSize + sizeof(UINT32), NULL);
  #endif
    if (pvChunk)
    {
        /* First UINT32 is used to store size of memory chunk */
        *(UINT32*)pvChunk = dwSize;

        return (MEMHANDLE) ((UINT32*)pvChunk + 1);
    }

    MTX_ERROR("in mtxvxd: failed to alloc memory\n");

    /* Allocation failed */
    return (MEMHANDLE) NULL;
}


I think the offending line is:
 pvChunk = ClientMemAlloc(dwSize + sizeof(UINT32), NULL) 


because that's what the log file tells me.

I'd be happy to email a copy of the log file and the file from which this snippet originated. I'm hoping someone on the other end of the intelligence bathtub curve can spot the error that this nincompoop (me) can't detect.

[fyi]The system is a 16 core HP DL580 G4 with 8g RAM, RAID 0, Mandrivalinux 11.0 and the display is a Matrox Parhelia 256PCIx.[/fyi]


Yours especially
Peter :-)

BTW: please be aware there is a similar post in another message on this board but the solution seemed not to be entered into.
Last edited on
What does ClientMemAlloc return?

From the error it sounds like it returns an integer instead of a pointer.

If that's the case, I would double-check to make sure you're using that function properly, as that doesn't seem right to me.

I think the offending line is:


It doesn't tell you the exact line number? That's pretty strange.
Yes, the log provides a line number. For example:

 
MtxMem.c: In function ‘memFileAlloc’:
MtxMem.c:79:13: warning: assignment makes pointer from integer without a cast [enabled by default


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
70  STACK_LINKAGE MEMHANDLE memFileAlloc(
71      UINT32 dwSize,
72      const char* pszFileName,
73      int iLine)
74  {
75     void* pvChunk;
76   #if MEMORY_STATS
77     pvChunk = ClientMemStatsAlloc(dwSize + sizeof(UINT32), pszFileName, iLine);
78   #else
79     pvChunk = ClientMemAlloc(dwSize + sizeof(UINT32), NULL);
80   #endif
81     if (pvChunk)
82    {
83         /* First UINT32 is used to store size of memory chunk */
84        *(UINT32*)pvChunk = dwSize;
85
86        return (MEMHANDLE) ((UINT32*)pvChunk + 1);
87     }
88
89    MTX_ERROR("in mtxvxd: failed to alloc memory\n");
90
91    /* Allocation failed */
92    return (MEMHANDLE) NULL;
93 }



From the error it sounds like it returns an integer instead of a pointer.


From what I (mis)understand from the log it is making a pointer from the integer. In the followup to this post I will post the log file and the file containing the code for you.
Here is the log file: make.log


Using kernel headers in /lib/modules/2.6.39.4-5.1-server/source/include for kernel version 2.6.x
making all in /parhelia...
make[1]: Entering directory `/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia'
making all in /mtxvxd...
make[1]: Entering directory `/root/matroxdriver-x86_64-1.4.6/kernel/src/mtxvxd'
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxCpu.c -o MtxCpu.o
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxCs.c -o MtxCs.o
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxIo.c -o MtxIo.o
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxMem.c -o MtxMem.o
MtxMem.c: In function ‘memFileAlloc’:
MtxMem.c:79:13: warning: assignment makes pointer from integer without a cast [enabled by default]
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxPci.c -o MtxPci.o
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxMap.c -o MtxMap.o
gcc   -DMEMORY_STATS=0  -DOS_LINUX -D__KERNEL__ -mcmodel=kernel -mno-red-zone  -O2 -fomit-frame-pointer -finline-functions  -DMODULE -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include -I/root/matroxdriver-x86_64-1.4.6/kernel/src/../include/mtxvxd -I/root/matroxdriver-x86_64-1.4.6/kernel/src -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia -I/root/matroxdriver-x86_64-1.4.6/kernel/src/parhelia/Main -I/lib/modules/2.6.39.4-5.1-server/source/include -I/lib/modules/2.6.39.4-5.1-server/source/include/asm/mach-default  -D__NO_VERSION__ -c MtxDbg.c -o MtxDbg.o
ld -r MtxCpu.o MtxCs.o MtxIo.o MtxMem.o MtxPci.o MtxMap.o MtxDbg.o -o mtxvxd.o
make[1]: Leaving directory `/root/matroxdriver-x86_64-1.4.6/kernel/src/mtxvxd'
make -C /lib/modules/2.6.39.4-5.1-server/build M=/root/matroxdriver-x86_64-1.4.6/kernel/src modules
make[1]: Entering directory `/usr/src/devel/2.6.39.4-5.1-server'
  CC [M]  /root/matroxdriver-x86_64-1.4.6/kernel/src/mtx_drv.o
gcc: error: -pg and -fomit-frame-pointer are incompatible
make[2]: *** [/root/matroxdriver-x86_64-1.4.6/kernel/src/mtx_drv.o] Error 1
make[1]: *** [_module_/root/matroxdriver-x86_64-1.4.6/kernel/src] Error 2
make[1]: Leaving directory `/usr/src/devel/2.6.39.4-5.1-server'
make: *** [default] Error 2


and in the next post the entire MtxMem.c file...

Nope, it isn't. The board wont let me post it. Feel free to email me at peterlowrie@vodafone.co.nz for a copy of the file .

Thank you
Peter
Last edited on
I don't need a copy of the file. Just let me know the return type of the ClientMemAlloc function. Is it void*?
Yes, i think...

void* pvChunk;

As above, I put the line numbers in that correspond to the line numbers in the offending file.

:-) Peter
Last edited on
Yes, i think...


I'm saying you should double-check, because the error suggests that it doesn't return that.

Yes pvChunk is a void*. But the error is saying you're converting an int to a void* without a cast. Which makes me think that ClientMemAlloc is returning an int, not a void* as you expect.

Either that or the value you're passing as the first parameter (dwSize + sizeof(UINT32)) is the int and the function is expecting a void* for that paramter. In which case the parameters you're passing are incorrect.


Whatever the case, it's clear that you need to find the definition of ClientMemAlloc and figure out what it returns and what parameters it takes. Because you're not using it correctly in the code you have now.

So either dig up any documentation on that function you have... or find its definition in the source code.
Methinks it's part of memmory management as called/used by system modules. I think the parameter you refer to is here:

EXTERN_C STACK_LINKAGE void* ClientMemAlloc(size_t size, HREGION region).

Is reported in the log thus
MtxMem.c: In function ‘memFileAlloc’:
MtxMem.c:79:5: error: too few arguments to function ‘ClientMemAlloc’
/root/matroxdriver-x86_64-cvs-20090511/kernel/src/mtx_client.h:41:30: note: declared here


However the term ClientMemAlloc in
1
2
3
if (ClientMemAlloc((region->size + (PAGE_SIZE - 1)) & PAGE_MASK, 
                               (HREGION)region) == 0)
            {

produces no logged errors.

Aha. That bit's fixed but the error in
/mtx_client.h:41:30
is

EXTERN_C STACK_LINKAGE void* ClientMemAlloc(size_t size, HREGION, region);

which tells me 'region' is now an unknown type. BTW, the code was written by the geniuses at Matrox. The only support Suse and RH. Because I choose to use Mandriva they won't lift a finger. Makes me want to blow them a raspberry.

:-)Peter
Last edited on
which tells me 'region' is now an unknown type.


That's because you've inserted a comma after HREGION and before region that shouldn't be there.
Last edited on
Dear cire and disch,

I took out the comma, saved and recompiled. Then I get this error along with stacks more that my 6th sense tells me is related to the two files; MtxMem.c and mtx_client.h mentioned immediately below.

MtxMem.c: In function ‘memFileAlloc’:
MtxMem.c:79:5: warning: passing argument 2 of ‘ClientMemAlloc’ makes integer from pointer without a cast [enabled by default]
mtx_client.h:41:30: note: expected ‘HREGION’ but argument is of type ‘void *’


I've tried already placing HREGION between brackets, braces et al but I keep getting the same reference back to
ClientMemAlloc
.

MtxMem.c:79 is pvChunk = ClientMemAlloc(dwSize + sizeof(UINT32), NULL); as above also. and mtx_client.h:41 is EXTERN_C STACK_LINKAGE void* ClientMemAlloc(size_t size, HREGION region); as we have been discussing.

So I have the sneaking suspicion the following relates to these two above:


mtx_drv.h: In function ‘GetPciName’:
mtx_drv.h:407:5: warning: return discards ‘const’ qualifier from pointer target type [enabled by default]
In file included from mtx_dev.c:20:0:
mtx_drv.h: In function ‘GetPciName’:
mtx_drv.h:407:5: warning: return discards ‘const’ qualifier from pointer target type [enabled by default]
In file included from mtx_ctx.c:16:0:
mtx_drv.h: In function ‘GetPciName’:
mtx_drv.h:407:5: warning: return discards ‘const’ qualifier from pointer target type [enabled by default]
In file included from mtx_mem.c:15:0:
mtx_drv.h: In function ‘GetPciName’:
mtx_drv.h:407:5: warning: return discards ‘const’ qualifier from pointer target type [enabled by default]
mtx_mem.c: In function ‘mtx_mem_alloc_agp’:
mtx_mem.c:267:5: warning: passing argument 1 of ‘agp_allocate_memory’ makes pointer from integer without a cast [enabled by default]
agp_backend.h:101:27: note: expected ‘struct agp_bridge_data *’ but argument is of type ‘ULONG’
mtx_mem.c:267:5: error: too few arguments to function ‘agp_allocate_memory’
agp_backend.h:101:27: note: declared here


mtx_drv.h:407(+,-)
1
2
3
4
5
6
7
8
INLINE char* GetPciName(struct pci_dev* pPciDev )
{
#ifdef KERNEL_2_6
  return pci_name(pPciDev);
#else
    return pPciDev->name;
#endif
}


Line 407 in the above snippet is return pci_name(pPciDev);

mtx_mem.c:267 info_block = MTX_AGPGART_ALLOCATE_MEMORY(agp_backend, pg_count, AGP_NORMAL_MEMORY);

Please be aware that agp_backend.h is a Linux system include file, agp_backend.h:101 extern struct agp_memory *agp_allocate_memory(struct agp_bridge_data *, size_t, u32);.

Thank you for continuing to help and bless your cottonsox.
Peter
Is HREGION a define or typedef for an int type? It seems like the function ClientMemAlloc does not accept pointers at all.

I can't really say anything about your other errors.
I pulled the whole thing into kate and used it's make/debug functions and I think the situation is now solved and we can put this matter to bed now.

There is other stuff like static spinlock_t g_oMtxInterlock = SPIN_LOCK_UNLOCKED;

but I think it's safe to enter this into another forum post if I can't debug it.

Muchos thank you for your help - all.

Peter
Topic archived. No new replies allowed.