]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
treewide: kmalloc() -> kmalloc_array()
authorKees Cook <keescook@chromium.org>
Tue, 12 Jun 2018 20:55:00 +0000 (13:55 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 12 Jun 2018 23:19:22 +0000 (16:19 -0700)
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:

        kmalloc(a * b, gfp)

with:
        kmalloc_array(a * b, gfp)

as well as handling cases of:

        kmalloc(a * b * c, gfp)

with:

        kmalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kmalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kmalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
  , ...)
|
  kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(u8) * COUNT
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(char) * COUNT
+ COUNT
  , ...)
|
  kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kmalloc
+ kmalloc_array
  (
- SIZE * COUNT
+ COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kmalloc(sizeof(THING) * C2, ...)
|
  kmalloc(sizeof(TYPE) * C2, ...)
|
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- sizeof(THING) * E2
+ E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- (E1) * E2
+ E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- (E1) * (E2)
+ E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
- E1 * E2
+ E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
377 files changed:
arch/arm/kernel/sys_oabi-compat.c
arch/arm/mm/pgd.c
arch/arm/probes/kprobes/test-core.c
arch/ia64/kernel/mca_drv.c
arch/ia64/mm/tlb.c
arch/ia64/sn/kernel/irq.c
arch/mips/alchemy/common/dbdma.c
arch/powerpc/lib/rheap.c
arch/powerpc/platforms/4xx/hsta_msi.c
arch/powerpc/platforms/4xx/msi.c
arch/powerpc/sysdev/mpic.c
arch/s390/hypfs/hypfs_diag0c.c
arch/s390/kernel/debug.c
arch/s390/kernel/perf_cpum_cf_events.c
arch/s390/mm/extmem.c
arch/sparc/kernel/nmi.c
arch/sparc/kernel/sys_sparc_64.c
arch/sparc/net/bpf_jit_comp_32.c
arch/um/drivers/ubd_kern.c
arch/um/drivers/vector_kern.c
arch/unicore32/kernel/pm.c
arch/x86/events/core.c
arch/x86/kernel/hpet.c
arch/x86/kernel/ksysfs.c
arch/x86/kvm/svm.c
arch/x86/net/bpf_jit_comp.c
arch/x86/net/bpf_jit_comp32.c
arch/x86/platform/uv/tlb_uv.c
block/partitions/ldm.c
crypto/testmgr.c
drivers/acpi/acpi_video.c
drivers/acpi/apei/hest.c
drivers/acpi/processor_perflib.c
drivers/acpi/processor_throttling.c
drivers/atm/solos-pci.c
drivers/auxdisplay/cfag12864b.c
drivers/block/DAC960.c
drivers/block/loop.c
drivers/block/z2ram.c
drivers/cdrom/cdrom.c
drivers/char/agp/compat_ioctl.c
drivers/char/agp/isoch.c
drivers/char/agp/sgi-agp.c
drivers/char/agp/uninorth-agp.c
drivers/char/virtio_console.c
drivers/cpufreq/bmips-cpufreq.c
drivers/crypto/chelsio/chtls/chtls_io.c
drivers/crypto/stm32/stm32-hash.c
drivers/dma/bestcomm/bestcomm.c
drivers/dma/mv_xor.c
drivers/firewire/core-iso.c
drivers/firewire/net.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
drivers/gpu/drm/drm_edid.c
drivers/gpu/drm/gma500/mid_bios.c
drivers/gpu/drm/nouveau/nvif/mmu.c
drivers/gpu/drm/nouveau/nvif/vmm.c
drivers/gpu/drm/nouveau/nvkm/subdev/bios/iccsense.c
drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgt215.c
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
drivers/gpu/drm/omapdrm/omap_gem.c
drivers/gpu/drm/qxl/qxl_kms.c
drivers/gpu/drm/savage/savage_bci.c
drivers/gpu/drm/tinydrm/repaper.c
drivers/gpu/drm/ttm/ttm_page_alloc.c
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
drivers/gpu/drm/vc4/vc4_plane.c
drivers/hid/hid-core.c
drivers/hid/hid-debug.c
drivers/hid/hid-picolcd_fb.c
drivers/hid/hidraw.c
drivers/i2c/i2c-dev.c
drivers/ide/ide-probe.c
drivers/infiniband/core/cma.c
drivers/infiniband/core/fmr_pool.c
drivers/infiniband/hw/cxgb4/id_table.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mthca/mthca_allocator.c
drivers/infiniband/hw/mthca/mthca_cmd.c
drivers/infiniband/hw/mthca/mthca_eq.c
drivers/infiniband/hw/mthca/mthca_memfree.c
drivers/infiniband/hw/mthca/mthca_mr.c
drivers/infiniband/hw/mthca/mthca_qp.c
drivers/infiniband/hw/mthca/mthca_srq.c
drivers/infiniband/hw/nes/nes_nic.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/hw/qib/qib_iba6120.c
drivers/infiniband/hw/qib/qib_iba7220.c
drivers/infiniband/hw/qib/qib_iba7322.c
drivers/infiniband/ulp/iser/iser_initiator.c
drivers/infiniband/ulp/srp/ib_srp.c
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/input/joystick/joydump.c
drivers/irqchip/irq-gic-v3-its.c
drivers/isdn/capi/capidrv.c
drivers/isdn/gigaset/capi.c
drivers/isdn/gigaset/common.c
drivers/isdn/hisax/hfc_2bds0.c
drivers/isdn/hisax/hfc_2bs0.c
drivers/isdn/hisax/netjet.c
drivers/isdn/i4l/isdn_common.c
drivers/lightnvm/pblk-init.c
drivers/md/dm-integrity.c
drivers/md/dm-snap.c
drivers/md/dm-stats.c
drivers/md/dm-table.c
drivers/md/md-bitmap.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/media/pci/bt8xx/bttv-risc.c
drivers/media/pci/ivtv/ivtvfb.c
drivers/media/platform/vivid/vivid-core.c
drivers/media/usb/cpia2/cpia2_usb.c
drivers/media/usb/cx231xx/cx231xx-audio.c
drivers/media/usb/go7007/go7007-usb.c
drivers/media/usb/gspca/t613.c
drivers/media/usb/stk1160/stk1160-core.c
drivers/media/usb/tm6000/tm6000-video.c
drivers/media/usb/usbvision/usbvision-video.c
drivers/media/usb/uvc/uvc_video.c
drivers/media/v4l2-core/videobuf-dma-sg.c
drivers/memstick/core/ms_block.c
drivers/message/fusion/mptlan.c
drivers/misc/eeprom/idt_89hpesx.c
drivers/misc/vmw_vmci/vmci_queue_pair.c
drivers/mtd/chips/cfi_cmdset_0001.c
drivers/mtd/chips/cfi_cmdset_0002.c
drivers/mtd/chips/cfi_cmdset_0020.c
drivers/mtd/ftl.c
drivers/mtd/inftlmount.c
drivers/mtd/lpddr/lpddr_cmds.c
drivers/mtd/maps/vmu-flash.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdswap.c
drivers/mtd/nand/raw/nand_bch.c
drivers/mtd/nftlmount.c
drivers/mtd/sm_ftl.c
drivers/mtd/ssfdc.c
drivers/mtd/tests/stresstest.c
drivers/mtd/ubi/eba.c
drivers/net/ethernet/amd/lance.c
drivers/net/ethernet/atheros/atl1c/atl1c_ethtool.c
drivers/net/ethernet/atheros/atl1e/atl1e_ethtool.c
drivers/net/ethernet/atheros/atlx/atl2.c
drivers/net/ethernet/broadcom/bnx2.c
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
drivers/net/ethernet/freescale/ucc_geth.c
drivers/net/ethernet/ibm/ibmveth.c
drivers/net/ethernet/intel/e1000/e1000_ethtool.c
drivers/net/ethernet/intel/e1000e/ethtool.c
drivers/net/ethernet/intel/igb/igb_ethtool.c
drivers/net/ethernet/intel/ixgb/ixgb_ethtool.c
drivers/net/ethernet/intel/ixgb/ixgb_main.c
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/mellanox/mlx4/eq.c
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
drivers/net/ethernet/moxa/moxart_ether.c
drivers/net/ethernet/nvidia/forcedeth.c
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
drivers/net/ethernet/qlogic/qed/qed_mcp.c
drivers/net/ethernet/qlogic/qlge/qlge_main.c
drivers/net/gtp.c
drivers/net/hippi/rrunner.c
drivers/net/team/team.c
drivers/net/usb/asix_common.c
drivers/net/usb/ax88179_178a.c
drivers/net/usb/usbnet.c
drivers/net/virtio_net.c
drivers/net/wireless/ath/ath5k/phy.c
drivers/net/wireless/ath/ath9k/ar9003_paprd.c
drivers/net/wireless/ath/ath9k/hw.c
drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c
drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_n.c
drivers/net/wireless/cisco/airo.c
drivers/net/wireless/intel/ipw2x00/ipw2100.c
drivers/net/wireless/intel/ipw2x00/ipw2200.c
drivers/net/wireless/intersil/hostap/hostap_info.c
drivers/net/wireless/intersil/hostap/hostap_ioctl.c
drivers/net/wireless/zydas/zd1211rw/zd_mac.c
drivers/pcmcia/cistpl.c
drivers/pinctrl/freescale/pinctrl-imx.c
drivers/pinctrl/freescale/pinctrl-imx1-core.c
drivers/pinctrl/sunxi/pinctrl-sunxi.c
drivers/s390/block/dasd_eer.c
drivers/s390/char/tty3270.c
drivers/s390/crypto/pkey_api.c
drivers/scsi/aacraid/aachba.c
drivers/scsi/aha1542.c
drivers/scsi/aic7xxx/aic79xx_core.c
drivers/scsi/aic94xx/aic94xx_hwi.c
drivers/scsi/arm/queue.c
drivers/scsi/be2iscsi/be_main.c
drivers/scsi/fcoe/fcoe_ctlr.c
drivers/scsi/hpsa.c
drivers/scsi/lpfc/lpfc_mem.c
drivers/scsi/mac53c94.c
drivers/scsi/megaraid.c
drivers/scsi/megaraid/megaraid_mm.c
drivers/scsi/osst.c
drivers/scsi/qla2xxx/qla_nx.c
drivers/scsi/qla4xxx/ql4_nx.c
drivers/scsi/smartpqi/smartpqi_init.c
drivers/scsi/st.c
drivers/scsi/virtio_scsi.c
drivers/soc/fsl/qbman/qman.c
drivers/staging/media/zoran/zoran_driver.c
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
drivers/staging/rtl8192u/r8192U_core.c
drivers/tty/hvc/hvcs.c
drivers/tty/isicom.c
drivers/tty/serial/atmel_serial.c
drivers/tty/vt/consolemap.c
drivers/tty/vt/keyboard.c
drivers/tty/vt/selection.c
drivers/usb/core/devio.c
drivers/usb/core/message.c
drivers/usb/host/fhci-tds.c
drivers/usb/host/ohci-dbg.c
drivers/usb/misc/ldusb.c
drivers/usb/serial/iuu_phoenix.c
drivers/usb/storage/alauda.c
drivers/usb/storage/ene_ub6250.c
drivers/usb/storage/sddr09.c
drivers/usb/storage/sddr55.c
drivers/uwb/est.c
drivers/uwb/i1480/dfu/usb.c
drivers/vhost/net.c
drivers/vhost/scsi.c
drivers/vhost/test.c
drivers/vhost/vhost.c
drivers/vhost/vringh.c
drivers/video/fbdev/core/bitblit.c
drivers/video/fbdev/core/fbcon.c
drivers/video/fbdev/core/fbcon_ccw.c
drivers/video/fbdev/core/fbcon_cw.c
drivers/video/fbdev/core/fbcon_rotate.c
drivers/video/fbdev/core/fbcon_ud.c
drivers/video/fbdev/core/fbmem.c
drivers/video/fbdev/core/fbmon.c
drivers/video/fbdev/imxfb.c
drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
drivers/video/fbdev/nvidia/nvidia.c
drivers/video/fbdev/pvr2fb.c
drivers/video/fbdev/riva/fbdev.c
drivers/video/fbdev/via/viafbdev.c
drivers/video/fbdev/w100fb.c
drivers/virt/vboxguest/vboxguest_core.c
drivers/virtio/virtio_pci_common.c
drivers/virtio/virtio_ring.c
drivers/xen/grant-table.c
drivers/xen/xen-pciback/pciback_ops.c
fs/9p/fid.c
fs/adfs/super.c
fs/afs/cmservice.c
fs/binfmt_elf.c
fs/binfmt_elf_fdpic.c
fs/block_dev.c
fs/ceph/addr.c
fs/ceph/mds_client.c
fs/cifs/asn1.c
fs/cifs/cifsacl.c
fs/cifs/inode.c
fs/cifs/smb2pdu.c
fs/cifs/transport.c
fs/exofs/inode.c
fs/ext2/super.c
fs/ext4/resize.c
fs/fat/namei_vfat.c
fs/fuse/dev.c
fs/gfs2/dir.c
fs/gfs2/glock.c
fs/gfs2/quota.c
fs/gfs2/rgrp.c
fs/gfs2/super.c
fs/hpfs/dnode.c
fs/hpfs/map.c
fs/jbd2/revoke.c
fs/jffs2/wbuf.c
fs/jfs/jfs_dmap.c
fs/jfs/jfs_dtree.c
fs/jfs/jfs_unicode.c
fs/mbcache.c
fs/namei.c
fs/nfsd/nfs4recover.c
fs/nfsd/nfs4state.c
fs/ntfs/compress.c
fs/ocfs2/cluster/tcp.c
fs/ocfs2/dlm/dlmdomain.c
fs/proc/base.c
fs/proc/task_mmu.c
fs/read_write.c
fs/reiserfs/journal.c
fs/select.c
fs/splice.c
fs/ubifs/lpt.c
fs/ubifs/super.c
fs/ubifs/tnc.c
fs/ubifs/tnc_commit.c
fs/ufs/super.c
kernel/bpf/lpm_trie.c
kernel/cgroup/cgroup-v1.c
kernel/cgroup/cpuset.c
kernel/debug/kdb/kdb_main.c
kernel/fail_function.c
kernel/locking/locktorture.c
kernel/relay.c
kernel/sched/topology.c
kernel/trace/ftrace.c
kernel/trace/trace.c
kernel/trace/trace_events_filter.c
kernel/user_namespace.c
lib/argv_split.c
lib/interval_tree_test.c
lib/kfifo.c
lib/mpi/mpiutil.c
lib/rbtree_test.c
lib/reed_solomon/reed_solomon.c
lib/scatterlist.c
mm/huge_memory.c
mm/hugetlb.c
mm/slub.c
net/9p/protocol.c
net/9p/trans_virtio.c
net/atm/mpc.c
net/bluetooth/hci_core.c
net/bluetooth/l2cap_core.c
net/can/bcm.c
net/ceph/osdmap.c
net/ceph/pagevec.c
net/core/dev.c
net/core/ethtool.c
net/dcb/dcbnl.c
net/dccp/ccids/ccid2.c
net/ipv4/route.c
net/mac80211/main.c
net/mac80211/rc80211_minstrel.c
net/mac80211/rc80211_minstrel_ht.c
net/netfilter/nf_conntrack_proto.c
net/netfilter/nf_nat_core.c
net/netfilter/nf_tables_api.c
net/netfilter/x_tables.c
net/netlink/genetlink.c
net/openvswitch/datapath.c
net/rds/info.c
net/rxrpc/rxkad.c
net/sctp/protocol.c
net/sunrpc/auth_gss/auth_gss.c
net/tipc/netlink_compat.c
security/keys/trusted.c
sound/core/pcm_compat.c
sound/core/pcm_native.c
sound/core/seq/seq_midi_emul.c
sound/firewire/packets-buffer.c
sound/oss/dmasound/dmasound_core.c
sound/pci/cs46xx/cs46xx_lib.c
sound/pci/cs46xx/dsp_spos.c
sound/pci/emu10k1/emufx.c
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_proc.c
sound/pci/via82xx.c
sound/pci/via82xx_modem.c
sound/pci/ymfpci/ymfpci_main.c
sound/soc/codecs/wm8904.c
sound/soc/codecs/wm8958-dsp2.c
sound/usb/caiaq/audio.c
sound/usb/format.c
sound/usb/line6/pcm.c
sound/usb/mixer.c
sound/usb/pcm.c
sound/usb/usx2y/usbusx2y.c
sound/usb/usx2y/usbusx2yaudio.c

index b9786f491873fae6a2f448e85b3fd76eb7511665..1df21a61e379e1a0fe66e784c7a1212814b100da 100644 (file)
@@ -286,7 +286,7 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
                return -EINVAL;
        if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
                return -EFAULT;
-       kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL);
+       kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
        if (!kbuf)
                return -ENOMEM;
        fs = get_fs();
@@ -324,7 +324,7 @@ asmlinkage long sys_oabi_semtimedop(int semid,
                return -EINVAL;
        if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
                return -EFAULT;
-       sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
+       sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
        if (!sops)
                return -ENOMEM;
        err = 0;
index 61e281cb29fb8280e00c88a3ebd0a575645a8c4e..a1606d9502515d5701899c934e9f81fc94c67d2d 100644 (file)
@@ -20,7 +20,7 @@
 #include "mm.h"
 
 #ifdef CONFIG_ARM_LPAE
-#define __pgd_alloc()  kmalloc(PTRS_PER_PGD * sizeof(pgd_t), GFP_KERNEL)
+#define __pgd_alloc()  kmalloc_array(PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL)
 #define __pgd_free(pgd)        kfree(pgd)
 #else
 #define __pgd_alloc()  (pgd_t *)__get_free_pages(GFP_KERNEL, 2)
index 9ed0129bed3ce3d2904740c9efa24256c3088e18..14db14152909c9942978c370b3d8230bc5ae4508 100644 (file)
@@ -766,8 +766,9 @@ static int coverage_start_fn(const struct decode_header *h, void *args)
 
 static int coverage_start(const union decode_item *table)
 {
-       coverage.base = kmalloc(MAX_COVERAGE_ENTRIES *
-                               sizeof(struct coverage_entry), GFP_KERNEL);
+       coverage.base = kmalloc_array(MAX_COVERAGE_ENTRIES,
+                                     sizeof(struct coverage_entry),
+                                     GFP_KERNEL);
        coverage.num_entries = 0;
        coverage.nesting = 0;
        return table_iter(table, coverage_start_fn, &coverage);
index 94f8bf777afa62d84e74cc3456959e2090d0f6f5..dfe40cbdf3b39a70b3812eaa65484618634e7575 100644 (file)
@@ -350,7 +350,8 @@ init_record_index_pools(void)
        /* - 3 - */
        slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
        slidx_pool.buffer =
-               kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
+               kmalloc_array(slidx_pool.max_idx, sizeof(slidx_list_t),
+                             GFP_KERNEL);
 
        return slidx_pool.buffer ? 0 : -ENOMEM;
 }
index 46ecc5d948aae84c553ab5386f969072b968a85e..acf10eb9da15c13252411746fe603785a61bffd7 100644 (file)
@@ -430,8 +430,9 @@ int ia64_itr_entry(u64 target_mask, u64 va, u64 pte, u64 log_size)
        int cpu = smp_processor_id();
 
        if (!ia64_idtrs[cpu]) {
-               ia64_idtrs[cpu] = kmalloc(2 * IA64_TR_ALLOC_MAX *
-                               sizeof (struct ia64_tr_entry), GFP_KERNEL);
+               ia64_idtrs[cpu] = kmalloc_array(2 * IA64_TR_ALLOC_MAX,
+                                               sizeof(struct ia64_tr_entry),
+                                               GFP_KERNEL);
                if (!ia64_idtrs[cpu])
                        return -ENOMEM;
        }
index 85d095154902453fb5896734597e849af07ea74e..d9b576df4f826c0c672d6a5d9164272f6aafa131 100644 (file)
@@ -474,7 +474,8 @@ void __init sn_irq_lh_init(void)
 {
        int i;
 
-       sn_irq_lh = kmalloc(sizeof(struct list_head *) * NR_IRQS, GFP_KERNEL);
+       sn_irq_lh = kmalloc_array(NR_IRQS, sizeof(struct list_head *),
+                                 GFP_KERNEL);
        if (!sn_irq_lh)
                panic("SN PCI INIT: Failed to allocate memory for PCI init\n");
 
index fc482d900dddba69eca81d08df77ccff5fb10998..24b04758cce522c57c0499db68f64a5f6ea4d453 100644 (file)
@@ -411,8 +411,8 @@ u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries)
         * and if we try that first we are likely to not waste larger
         * slabs of memory.
         */
-       desc_base = (u32)kmalloc(entries * sizeof(au1x_ddma_desc_t),
-                                GFP_KERNEL|GFP_DMA);
+       desc_base = (u32)kmalloc_array(entries, sizeof(au1x_ddma_desc_t),
+                                      GFP_KERNEL|GFP_DMA);
        if (desc_base == 0)
                return 0;
 
index 94058c21a4827697bb964ff9acb542b0c42d6471..6aa774aa5b16974d46d510d322912c992006bcde 100644 (file)
@@ -54,7 +54,7 @@ static int grow(rh_info_t * info, int max_blocks)
 
        new_blocks = max_blocks - info->max_blocks;
 
-       block = kmalloc(sizeof(rh_block_t) * max_blocks, GFP_ATOMIC);
+       block = kmalloc_array(max_blocks, sizeof(rh_block_t), GFP_ATOMIC);
        if (block == NULL)
                return -ENOMEM;
 
index 9926ad67af761acbfcc5dcf173bbaa55dc59f3d1..1c18f2955f7d38906a9743e3198c723726eeedf8 100644 (file)
@@ -156,7 +156,8 @@ static int hsta_msi_probe(struct platform_device *pdev)
        if (ret)
                goto out;
 
-       ppc4xx_hsta_msi.irq_map = kmalloc(sizeof(int) * irq_count, GFP_KERNEL);
+       ppc4xx_hsta_msi.irq_map = kmalloc_array(irq_count, sizeof(int),
+                                               GFP_KERNEL);
        if (!ppc4xx_hsta_msi.irq_map) {
                ret = -ENOMEM;
                goto out1;
index 96aaae67892802d9153d3f603c67437d5fe802eb..81b2cbce7df8703d0a09480865be5d9f95e3068b 100644 (file)
@@ -89,7 +89,7 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
        if (type == PCI_CAP_ID_MSIX)
                pr_debug("ppc4xx msi: MSI-X untested, trying anyway.\n");
 
-       msi_data->msi_virqs = kmalloc((msi_irqs) * sizeof(int), GFP_KERNEL);
+       msi_data->msi_virqs = kmalloc_array(msi_irqs, sizeof(int), GFP_KERNEL);
        if (!msi_data->msi_virqs)
                return -ENOMEM;
 
index 1d4e0ef658d38f4ba7deafa877d1250b82e1459c..df062a154ca8816bf0812f5fd209c034e6dab954 100644 (file)
@@ -1639,8 +1639,9 @@ void __init mpic_init(struct mpic *mpic)
 
 #ifdef CONFIG_PM
        /* allocate memory to save mpic state */
-       mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
-                                 GFP_KERNEL);
+       mpic->save_data = kmalloc_array(mpic->num_sources,
+                                       sizeof(*mpic->save_data),
+                                       GFP_KERNEL);
        BUG_ON(mpic->save_data == NULL);
 #endif
 
index dce87f1bec94672b31b633c9f02098f565fa9b25..cebf05150cc17e5757dbcb859e20a887f16d8845 100644 (file)
@@ -49,7 +49,8 @@ static void *diag0c_store(unsigned int *count)
 
        get_online_cpus();
        cpu_count = num_online_cpus();
-       cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
+       cpu_vec = kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec),
+                               GFP_KERNEL);
        if (!cpu_vec)
                goto fail_put_online_cpus;
        /* Note: Diag 0c needs 8 byte alignment and real storage */
index 80e974adb9e8be39d4ab558495eb69d110a2b3a3..d374f9b218b4c278101ebcd451c7304c0ef390a0 100644 (file)
@@ -194,11 +194,13 @@ static debug_entry_t ***debug_areas_alloc(int pages_per_area, int nr_areas)
        debug_entry_t ***areas;
        int i, j;
 
-       areas = kmalloc(nr_areas * sizeof(debug_entry_t **), GFP_KERNEL);
+       areas = kmalloc_array(nr_areas, sizeof(debug_entry_t **), GFP_KERNEL);
        if (!areas)
                goto fail_malloc_areas;
        for (i = 0; i < nr_areas; i++) {
-               areas[i] = kmalloc(pages_per_area * sizeof(debug_entry_t *), GFP_KERNEL);
+               areas[i] = kmalloc_array(pages_per_area,
+                                        sizeof(debug_entry_t *),
+                                        GFP_KERNEL);
                if (!areas[i])
                        goto fail_malloc_areas2;
                for (j = 0; j < pages_per_area; j++) {
index feebb294488203b77899f5415f841e12cefedf29..d63fb3c56b8ad891ac05ce725214d59a2dd4d72a 100644 (file)
@@ -527,7 +527,7 @@ static __init struct attribute **merge_attr(struct attribute **a,
                j++;
        j++;
 
-       new = kmalloc(sizeof(struct attribute *) * j, GFP_KERNEL);
+       new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
        if (!new)
                return NULL;
        j = 0;
index 920d408945359351e20e2ae397598390a0ad2f27..6ad15d3fab819d9f17109f7bd08c1d3311ea76ba 100644 (file)
@@ -103,7 +103,7 @@ static int scode_set;
 static int
 dcss_set_subcodes(void)
 {
-       char *name = kmalloc(8 * sizeof(char), GFP_KERNEL | GFP_DMA);
+       char *name = kmalloc(8, GFP_KERNEL | GFP_DMA);
        unsigned long rx, ry;
        int rc;
 
index 048ad783ea3fe45adfa5ce23d48a106910e02de4..8babbeb30adf9bee71b822bf9adc99cd905ec4f3 100644 (file)
@@ -166,7 +166,8 @@ static int __init check_nmi_watchdog(void)
        if (!atomic_read(&nmi_active))
                return 0;
 
-       prev_nmi_count = kmalloc(nr_cpu_ids * sizeof(unsigned int), GFP_KERNEL);
+       prev_nmi_count = kmalloc_array(nr_cpu_ids, sizeof(unsigned int),
+                                      GFP_KERNEL);
        if (!prev_nmi_count) {
                err = -ENOMEM;
                goto error;
index 7e49bbc925a575ebd78d3d79e61e3f6710e41904..33e351704f9ff91cb14749b2c1d150a5cc337207 100644 (file)
@@ -575,8 +575,9 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
                        unsigned long *p = current_thread_info()->utraps;
 
                        current_thread_info()->utraps =
-                               kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
-                                       GFP_KERNEL);
+                               kmalloc_array(UT_TRAP_INSTRUCTION_31 + 1,
+                                             sizeof(long),
+                                             GFP_KERNEL);
                        if (!current_thread_info()->utraps) {
                                current_thread_info()->utraps = p;
                                return -ENOMEM;
index 3bd8ca95e5210a5f7dd5c1700a90a650379de37a..a5ff88643d5c98aed49150b591f75ecb189fedc2 100644 (file)
@@ -335,7 +335,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
        if (!bpf_jit_enable)
                return;
 
-       addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
+       addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
        if (addrs == NULL)
                return;
 
index dcf5ea28a2815803977cc12757aa4b2c21a70e13..83c470364dfb34dce51320322e9b119c10157f3e 100644 (file)
@@ -1127,9 +1127,9 @@ static int __init ubd_init(void)
                        return -1;
        }
 
-       irq_req_buffer = kmalloc(
-                       sizeof(struct io_thread_req *) * UBD_REQ_BUFFER_SIZE,
-                       GFP_KERNEL
+       irq_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
+                                      sizeof(struct io_thread_req *),
+                                      GFP_KERNEL
                );
        irq_remainder = 0;
 
@@ -1137,9 +1137,9 @@ static int __init ubd_init(void)
                printk(KERN_ERR "Failed to initialize ubd buffering\n");
                return -1;
        }
-       io_req_buffer = kmalloc(
-                       sizeof(struct io_thread_req *) * UBD_REQ_BUFFER_SIZE,
-                       GFP_KERNEL
+       io_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
+                                     sizeof(struct io_thread_req *),
+                                     GFP_KERNEL
                );
 
        io_remainder = 0;
index 02168fe2510592f1ac7f8728e8c5004bf3e55a48..627075e6d8751e0732151f85e55390d14b447324 100644 (file)
@@ -527,14 +527,14 @@ static struct vector_queue *create_queue(
        result->max_iov_frags = num_extra_frags;
        for (i = 0; i < max_size; i++) {
                if (vp->header_size > 0)
-                       iov = kmalloc(
-                               sizeof(struct iovec) * (3 + num_extra_frags),
-                               GFP_KERNEL
+                       iov = kmalloc_array(3 + num_extra_frags,
+                                           sizeof(struct iovec),
+                                           GFP_KERNEL
                        );
                else
-                       iov = kmalloc(
-                               sizeof(struct iovec) * (2 + num_extra_frags),
-                               GFP_KERNEL
+                       iov = kmalloc_array(2 + num_extra_frags,
+                                           sizeof(struct iovec),
+                                           GFP_KERNEL
                        );
                if (iov == NULL)
                        goto out_fail;
index 784bc2db3b289bd7adc235fac6d30de81daac2a5..6f8164d91dc2e041d55cc97cb175bc07d82a3ea7 100644 (file)
@@ -109,8 +109,9 @@ static int __init puv3_pm_init(void)
                return -EINVAL;
        }
 
-       sleep_save = kmalloc(puv3_cpu_pm_fns->save_count
-                               * sizeof(unsigned long), GFP_KERNEL);
+       sleep_save = kmalloc_array(puv3_cpu_pm_fns->save_count,
+                                  sizeof(unsigned long),
+                                  GFP_KERNEL);
        if (!sleep_save) {
                printk(KERN_ERR "failed to alloc memory for pm save\n");
                return -ENOMEM;
index 6e461fb1e0d476f80def177b43c7cc01726d89ce..5f4829f10129c5bfd59b803d0ddd4a21be0b3107 100644 (file)
@@ -1637,7 +1637,7 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
                j++;
        j++;
 
-       new = kmalloc(sizeof(struct attribute *) * j, GFP_KERNEL);
+       new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
        if (!new)
                return NULL;
 
index b6be34ee88e9181219ad939b42744f8312cae9b5..ddccdea0b63b5b28c60b723069ad6938fa4f5bab 100644 (file)
@@ -966,8 +966,8 @@ int __init hpet_enable(void)
 #endif
 
        cfg = hpet_readl(HPET_CFG);
-       hpet_boot_cfg = kmalloc((last + 2) * sizeof(*hpet_boot_cfg),
-                               GFP_KERNEL);
+       hpet_boot_cfg = kmalloc_array(last + 2, sizeof(*hpet_boot_cfg),
+                                     GFP_KERNEL);
        if (hpet_boot_cfg)
                *hpet_boot_cfg = cfg;
        else
index 8c1cc08f514f4362bdaefa933fda3cd3769b04f9..163ae706a0d4f9d58975e6ddaf49313d89345e14 100644 (file)
@@ -283,7 +283,7 @@ static int __init create_setup_data_nodes(struct kobject *parent)
        if (ret)
                goto out_setup_data_kobj;
 
-       kobjp = kmalloc(sizeof(*kobjp) * nr, GFP_KERNEL);
+       kobjp = kmalloc_array(nr, sizeof(*kobjp), GFP_KERNEL);
        if (!kobjp) {
                ret = -ENOMEM;
                goto out_setup_data_kobj;
index 950ec50f77c30b71545fd93a4154875b4d9f0e4e..e831e6d3b70e15b60b73a0fb437f7ee7ed8c9e48 100644 (file)
@@ -1001,7 +1001,9 @@ static int svm_cpu_init(int cpu)
 
        if (svm_sev_enabled()) {
                r = -ENOMEM;
-               sd->sev_vmcbs = kmalloc((max_sev_asid + 1) * sizeof(void *), GFP_KERNEL);
+               sd->sev_vmcbs = kmalloc_array(max_sev_asid + 1,
+                                             sizeof(void *),
+                                             GFP_KERNEL);
                if (!sd->sev_vmcbs)
                        goto err_1;
        }
index 8fca446aaef62b92a79a5b76ac3a708aa249b935..2580cd2e98b1700f2bc048377d431a56dd69eccb 100644 (file)
@@ -1107,7 +1107,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
                extra_pass = true;
                goto skip_init_addrs;
        }
-       addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
+       addrs = kmalloc_array(prog->len, sizeof(*addrs), GFP_KERNEL);
        if (!addrs) {
                prog = orig_prog;
                goto out_addrs;
index 0cc04e30adc12f4badfce2d4185fba1564e4153b..55799873ebe53375b8cf492af137461bba00b9b8 100644 (file)
@@ -2345,7 +2345,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
                prog = tmp;
        }
 
-       addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
+       addrs = kmalloc_array(prog->len, sizeof(*addrs), GFP_KERNEL);
        if (!addrs) {
                prog = orig_prog;
                goto out;
index b96d38288c6005790c75f80dad4737477837fdea..ca446da48fd2872e262b789ebbfe12c2ec1d4976 100644 (file)
@@ -2142,7 +2142,7 @@ static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
        if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
                timeout_us = calculate_destination_timeout();
 
-       vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
+       vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
        uvhub_descs = (struct uvhub_desc *)vp;
        memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
        uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
index 2a365c756648ca66f55274a49cf1aaad2d1c96e8..0417937dfe9964eba13a62a10c963cba1f71421e 100644 (file)
@@ -378,7 +378,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
        BUG_ON(!state || !ldb);
        ph = &ldb->ph;
        tb[0] = &ldb->toc;
-       tb[1] = kmalloc(sizeof(*tb[1]) * 3, GFP_KERNEL);
+       tb[1] = kmalloc_array(3, sizeof(*tb[1]), GFP_KERNEL);
        if (!tb[1]) {
                ldm_crit("Out of memory.");
                goto err;
index d1d99843cce4d731f3cca0df1c3af6ec32d50308..11e45352fd0b825e25e7a80259a9c5c24bfc20f1 100644 (file)
@@ -603,7 +603,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
                goto out_nooutbuf;
 
        /* avoid "the frame size is larger than 1024 bytes" compiler warning */
-       sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
+       sg = kmalloc(array3_size(sizeof(*sg), 8, (diff_dst ? 4 : 2)),
+                    GFP_KERNEL);
        if (!sg)
                goto out_nosg;
        sgout = &sg[16];
index 2f2e737be0f84a966020102ba21ce906c21b9584..f0b52266b3ac6c45ea83a7f446513a179d60531b 100644 (file)
@@ -832,8 +832,9 @@ int acpi_video_get_levels(struct acpi_device *device,
         * in order to account for buggy BIOS which don't export the first two
         * special levels (see below)
         */
-       br->levels = kmalloc((obj->package.count + ACPI_VIDEO_FIRST_LEVEL) *
-                            sizeof(*br->levels), GFP_KERNEL);
+       br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL,
+                                  sizeof(*br->levels),
+                                  GFP_KERNEL);
        if (!br->levels) {
                result = -ENOMEM;
                goto out_free;
index 9cb74115a43d76bbfa845feb57ef779bf320f0ad..b1e9f81ebeea25b58ba6c0f9820ad38b4bc5b9e0 100644 (file)
@@ -195,7 +195,8 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
        struct ghes_arr ghes_arr;
 
        ghes_arr.count = 0;
-       ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
+       ghes_arr.ghes_devs = kmalloc_array(ghes_count, sizeof(void *),
+                                          GFP_KERNEL);
        if (!ghes_arr.ghes_devs)
                return -ENOMEM;
 
index a651ab3490d8bbbe843204c6065bb30c64f7dfb8..a303fd0e108ccbe8180d233462deea15b5f570f9 100644 (file)
@@ -343,8 +343,9 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
 
        pr->performance->state_count = pss->package.count;
        pr->performance->states =
-           kmalloc(sizeof(struct acpi_processor_px) * pss->package.count,
-                   GFP_KERNEL);
+           kmalloc_array(pss->package.count,
+                         sizeof(struct acpi_processor_px),
+                         GFP_KERNEL);
        if (!pr->performance->states) {
                result = -ENOMEM;
                goto end;
index 7f9aff4b8d627db3accf80a12054b698887a314d..fbc936cf2025c7eaa1d3a51d5463dcafabb3894c 100644 (file)
@@ -534,8 +534,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
 
        pr->throttling.state_count = tss->package.count;
        pr->throttling.states_tss =
-           kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
-                   GFP_KERNEL);
+           kmalloc_array(tss->package.count,
+                         sizeof(struct acpi_processor_tx_tss),
+                         GFP_KERNEL);
        if (!pr->throttling.states_tss) {
                result = -ENOMEM;
                goto end;
index 0df1a1c80b00126e7d6083de7a51328758d4742b..17283018269f0343df85e9c2bed32d6276d369a7 100644 (file)
@@ -1291,7 +1291,8 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
                card->using_dma = 1;
                if (1) { /* All known FPGA versions so far */
                        card->dma_alignment = 3;
-                       card->dma_bounce = kmalloc(card->nr_ports * BUF_SIZE, GFP_KERNEL);
+                       card->dma_bounce = kmalloc_array(card->nr_ports,
+                                                        BUF_SIZE, GFP_KERNEL);
                        if (!card->dma_bounce) {
                                dev_warn(&card->dev->dev, "Failed to allocate DMA bounce buffers\n");
                                err = -ENOMEM;
index 6bd2f65e116a0dee8986f10f5e83f654992eaa6d..7eebae7e322c605e97d2592223beb92ab82054c3 100644 (file)
@@ -333,8 +333,8 @@ static int __init cfag12864b_init(void)
                goto none;
        }
 
-       cfag12864b_cache = kmalloc(sizeof(unsigned char) *
-               CFAG12864B_SIZE, GFP_KERNEL);
+       cfag12864b_cache = kmalloc(CFAG12864B_SIZE,
+                                  GFP_KERNEL);
        if (cfag12864b_cache == NULL) {
                printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
                        "can't alloc cache buffer (%i bytes)\n",
index 6ca77d6047d619dd54ea5ef464af625d1712db8f..f6518067aa7d069009bd6a2215805f2ca71c6380 100644 (file)
@@ -5719,8 +5719,8 @@ static bool DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
       Controller->CombinedStatusBufferLength = NewStatusBufferLength;
       return true;
     }
-  NewStatusBuffer = kmalloc(2 * Controller->CombinedStatusBufferLength,
-                            GFP_ATOMIC);
+  NewStatusBuffer = kmalloc_array(2, Controller->CombinedStatusBufferLength,
+                                  GFP_ATOMIC);
   if (NewStatusBuffer == NULL)
     {
       DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
index 21e6d1b3b393448cea181f5e06f2978543b48a9a..d6b6f434fd4bb7652faf597ef9ab6c7b6dd7c362 100644 (file)
@@ -524,7 +524,8 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 
                __rq_for_each_bio(bio, rq)
                        segments += bio_segments(bio);
-               bvec = kmalloc(sizeof(struct bio_vec) * segments, GFP_NOIO);
+               bvec = kmalloc_array(segments, sizeof(struct bio_vec),
+                                    GFP_NOIO);
                if (!bvec)
                        return -EIO;
                cmd->bvec = bvec;
index 8f9130ab5887273d8feba518fabb76524fa7b579..d0c5bc4e07039bcaf1625e614b56093f7a0c4c46 100644 (file)
@@ -197,8 +197,9 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
                vaddr = (unsigned long)z_remap_nocache_nonser(paddr, size);
 #endif
                z2ram_map = 
-                       kmalloc((size/Z2RAM_CHUNKSIZE)*sizeof(z2ram_map[0]),
-                               GFP_KERNEL);
+                       kmalloc_array(size / Z2RAM_CHUNKSIZE,
+                                      sizeof(z2ram_map[0]),
+                                      GFP_KERNEL);
                if ( z2ram_map == NULL )
                {
                    printk( KERN_ERR DEVICE_NAME
index 9adc8c3eb0fa7affa56f8e9ade8bd2e62f8025a7..a78b8e7085e9bc71497e81002cd014776ff9767b 100644 (file)
@@ -2132,7 +2132,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
         */
        nr = nframes;
        do {
-               cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
+               cgc.buffer = kmalloc_array(nr, CD_FRAMESIZE_RAW, GFP_KERNEL);
                if (cgc.buffer)
                        break;
 
index 2053f70ef66b2de7c93700daf081f41a26442eef..52ffe1706ce0512e472992b0897c82e5e7c155fe 100644 (file)
@@ -98,11 +98,15 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
                if (ureserve.seg_count >= 16384)
                        return -EINVAL;
 
-               usegment = kmalloc(sizeof(*usegment) * ureserve.seg_count, GFP_KERNEL);
+               usegment = kmalloc_array(ureserve.seg_count,
+                                        sizeof(*usegment),
+                                        GFP_KERNEL);
                if (!usegment)
                        return -ENOMEM;
 
-               ksegment = kmalloc(sizeof(*ksegment) * kreserve.seg_count, GFP_KERNEL);
+               ksegment = kmalloc_array(kreserve.seg_count,
+                                        sizeof(*ksegment),
+                                        GFP_KERNEL);
                if (!ksegment) {
                        kfree(usegment);
                        return -ENOMEM;
index fc8e1bc3347d10853e0bdbb47b55ec8f73e040c6..31c374b1b91b038827254824b48bb91b8b577d68 100644 (file)
@@ -93,7 +93,8 @@ static int agp_3_5_isochronous_node_enable(struct agp_bridge_data *bridge,
         * We'll work with an array of isoch_data's (one for each
         * device in dev_list) throughout this function.
         */
-       if ((master = kmalloc(ndevs * sizeof(*master), GFP_KERNEL)) == NULL) {
+       master = kmalloc_array(ndevs, sizeof(*master), GFP_KERNEL);
+       if (master == NULL) {
                ret = -ENOMEM;
                goto get_out;
        }
index 3051c73bc3838a0ccdbc0784d7a5bac76d356cd2..e7d5bdc02d93d75daa05be0aabf370d073325028 100644 (file)
@@ -280,9 +280,9 @@ static int agp_sgi_init(void)
        else
                return 0;
 
-       sgi_tioca_agp_bridges = kmalloc(tioca_gart_found *
-                                       sizeof(struct agp_bridge_data *),
-                                       GFP_KERNEL);
+       sgi_tioca_agp_bridges = kmalloc_array(tioca_gart_found,
+                                             sizeof(struct agp_bridge_data *),
+                                             GFP_KERNEL);
        if (!sgi_tioca_agp_bridges)
                return -ENOMEM;
 
index 79d8c84693a185264990d40185006f5eaec0f145..31fcd04304263a21161d2e7aae378a2daa789995 100644 (file)
@@ -402,7 +402,9 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)
        if (table == NULL)
                return -ENOMEM;
 
-       uninorth_priv.pages_arr = kmalloc((1 << page_order) * sizeof(struct page*), GFP_KERNEL);
+       uninorth_priv.pages_arr = kmalloc_array(1 << page_order,
+                                               sizeof(struct page *),
+                                               GFP_KERNEL);
        if (uninorth_priv.pages_arr == NULL)
                goto enomem;
 
index 4bf7c06c2343e6e09d4fba3bb40254eb65072716..17084cfcf53ecdbcbf83f5efec201384da70aaa1 100644 (file)
@@ -1891,13 +1891,14 @@ static int init_vqs(struct ports_device *portdev)
        nr_ports = portdev->max_nr_ports;
        nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
 
-       vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
-       io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
-       io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
-       portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
-                                 GFP_KERNEL);
-       portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
-                                  GFP_KERNEL);
+       vqs = kmalloc_array(nr_queues, sizeof(struct virtqueue *), GFP_KERNEL);
+       io_callbacks = kmalloc_array(nr_queues, sizeof(vq_callback_t *),
+                                    GFP_KERNEL);
+       io_names = kmalloc_array(nr_queues, sizeof(char *), GFP_KERNEL);
+       portdev->in_vqs = kmalloc_array(nr_ports, sizeof(struct virtqueue *),
+                                       GFP_KERNEL);
+       portdev->out_vqs = kmalloc_array(nr_ports, sizeof(struct virtqueue *),
+                                        GFP_KERNEL);
        if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
            !portdev->out_vqs) {
                err = -ENOMEM;
index 1653151b77df31b9e78c039a9bf8f9df5dd89f0d..56a4ebbf00e02479b17cb3eb4efc1d2c830adefd 100644 (file)
@@ -71,7 +71,7 @@ bmips_cpufreq_get_freq_table(const struct cpufreq_policy *policy)
 
        cpu_freq = htp_freq_to_cpu_freq(priv->clk_mult);
 
-       table = kmalloc((priv->max_freqs + 1) * sizeof(*table), GFP_KERNEL);
+       table = kmalloc_array(priv->max_freqs + 1, sizeof(*table), GFP_KERNEL);
        if (!table)
                return ERR_PTR(-ENOMEM);
 
index 51fc6821cbbf4c1dd01a9e93c870923d539a64bf..00c7aab8e7d0f5861e778dc4d26affe5c1234603 100644 (file)
@@ -240,7 +240,7 @@ static int tls_copy_ivs(struct sock *sk, struct sk_buff *skb)
        }
 
        /* generate the  IVs */
-       ivs = kmalloc(number_of_ivs * CIPHER_BLOCK_SIZE, GFP_ATOMIC);
+       ivs = kmalloc_array(CIPHER_BLOCK_SIZE, number_of_ivs, GFP_ATOMIC);
        if (!ivs)
                return -ENOMEM;
        get_random_bytes(ivs, number_of_ivs * CIPHER_BLOCK_SIZE);
index 981e45692695a000bceac10a9f87727be194276b..cdc96f1bb917592dcad692d831a76f8db06251bd 100644 (file)
@@ -970,8 +970,9 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
        while (!(stm32_hash_read(hdev, HASH_SR) & HASH_SR_DATA_INPUT_READY))
                cpu_relax();
 
-       rctx->hw_context = kmalloc(sizeof(u32) * (3 + HASH_CSR_REGISTER_NUMBER),
-                                  GFP_KERNEL);
+       rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
+                                        sizeof(u32),
+                                        GFP_KERNEL);
 
        preg = rctx->hw_context;
 
index 7a67b83450928e4aeb02c1c3ef08e4fd71f0b94d..d91cbbe7a48fbe92027389d99542725bffe76831 100644 (file)
@@ -87,7 +87,8 @@ bcom_task_alloc(int bd_count, int bd_size, int priv_size)
 
        /* Init the BDs, if needed */
        if (bd_count) {
-               tsk->cookie = kmalloc(sizeof(void*) * bd_count, GFP_KERNEL);
+               tsk->cookie = kmalloc_array(bd_count, sizeof(void *),
+                                           GFP_KERNEL);
                if (!tsk->cookie)
                        goto error;
 
index 1993889003fd11d51d80090daf32737d740a5b4b..4528b560dc4c3db0457a05ec957f21f65d432bb4 100644 (file)
@@ -777,7 +777,7 @@ static int mv_chan_memcpy_self_test(struct mv_xor_chan *mv_chan)
        struct dmaengine_unmap_data *unmap;
        int err = 0;
 
-       src = kmalloc(sizeof(u8) * PAGE_SIZE, GFP_KERNEL);
+       src = kmalloc(PAGE_SIZE, GFP_KERNEL);
        if (!src)
                return -ENOMEM;
 
index 38c0aa60b2cb1a53da46547e5bc188a87db1f18b..051327a951b1955ad017c70d5d1fdba145c95b0b 100644 (file)
@@ -45,8 +45,8 @@ int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count)
 
        buffer->page_count = 0;
        buffer->page_count_mapped = 0;
-       buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
-                               GFP_KERNEL);
+       buffer->pages = kmalloc_array(page_count, sizeof(buffer->pages[0]),
+                                     GFP_KERNEL);
        if (buffer->pages == NULL)
                return -ENOMEM;
 
index 60e75e6d9104c3db01c8ca36b25b70f02bb70c83..82ba110d9d1ad29600c006dbe2cc350616a099b8 100644 (file)
@@ -1121,7 +1121,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev)
        max_receive = 1U << (dev->card->max_receive + 1);
        num_packets = (FWNET_ISO_PAGE_COUNT * PAGE_SIZE) / max_receive;
 
-       ptrptr = kmalloc(sizeof(void *) * num_packets, GFP_KERNEL);
+       ptrptr = kmalloc_array(num_packets, sizeof(void *), GFP_KERNEL);
        if (!ptrptr) {
                retval = -ENOMEM;
                goto failed;
index 0ff36d45a59700162211da3af89091114d2dd0a2..ea79908dac4cbcae178b5398b69aee12f4377ea8 100644 (file)
@@ -407,7 +407,7 @@ static int kgd_hqd_dump(struct kgd_dev *kgd,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -504,7 +504,7 @@ static int kgd_hqd_sdma_dump(struct kgd_dev *kgd,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+4)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index 6ef9762b4b007beeb9a26c8de0bd2fc6f02fc139..19dd665e7307130c0d7a8993815d249f3809cade 100644 (file)
@@ -395,7 +395,7 @@ static int kgd_hqd_dump(struct kgd_dev *kgd,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -491,7 +491,7 @@ static int kgd_hqd_sdma_dump(struct kgd_dev *kgd,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+4+2+3+7)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index f0c0d3953f6989496a6beab4da5053808892dd4e..1db60aa5b7f0eab0c012cc41af2181bb678a7813 100644 (file)
@@ -504,7 +504,7 @@ static int kgd_hqd_dump(struct kgd_dev *kgd,
                (*dump)[i++][1] = RREG32(addr);         \
        } while (0)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
@@ -606,7 +606,7 @@ static int kgd_hqd_sdma_dump(struct kgd_dev *kgd,
 #undef HQD_N_REGS
 #define HQD_N_REGS (19+6+7+10)
 
-       *dump = kmalloc(HQD_N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+       *dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
        if (*dump == NULL)
                return -ENOMEM;
 
index 40e1e24f2ff0847d3d9fd65bd2069b28ab9b2c2a..a5808382bdf0333b2124a4ecf0d85c4346814000 100644 (file)
@@ -1633,7 +1633,8 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
                edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
                edid[0x7e] = valid_extensions;
 
-               new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
+               new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
+                                   GFP_KERNEL);
                if (!new)
                        goto out;
 
index 7171b7475f589164020722fecf56bf8b56820ca7..237041a3753228bf420029cdbbb26a262f774a9a 100644 (file)
@@ -239,7 +239,7 @@ static int mid_get_vbt_data_r10(struct drm_psb_private *dev_priv, u32 addr)
        if (read_vbt_r10(addr, &vbt))
                return -1;
 
-       gct = kmalloc(sizeof(*gct) * vbt.panel_count, GFP_KERNEL);
+       gct = kmalloc_array(vbt.panel_count, sizeof(*gct), GFP_KERNEL);
        if (!gct)
                return -ENOMEM;
 
index 358ac4f3cf91d75a23d6844c36673d3aad832803..ae08a1ca804484b6329a5712474b158ea6b6d7ea 100644 (file)
@@ -65,12 +65,15 @@ nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu)
                goto done;
        mmu->mem = mems[ret].oclass;
 
-       mmu->heap = kmalloc(sizeof(*mmu->heap) * mmu->heap_nr, GFP_KERNEL);
-       mmu->type = kmalloc(sizeof(*mmu->type) * mmu->type_nr, GFP_KERNEL);
+       mmu->heap = kmalloc_array(mmu->heap_nr, sizeof(*mmu->heap),
+                                 GFP_KERNEL);
+       mmu->type = kmalloc_array(mmu->type_nr, sizeof(*mmu->type),
+                                 GFP_KERNEL);
        if (ret = -ENOMEM, !mmu->heap || !mmu->type)
                goto done;
 
-       mmu->kind = kmalloc(sizeof(*mmu->kind) * mmu->kind_nr, GFP_KERNEL);
+       mmu->kind = kmalloc_array(mmu->kind_nr, sizeof(*mmu->kind),
+                                 GFP_KERNEL);
        if (!mmu->kind && mmu->kind_nr)
                goto done;
 
index 191832be6c6586dd6f28fc5c83ea07e766fd5cdf..6b9c5776547f762829d5c6517d8d5fd98cfc1eee 100644 (file)
@@ -138,7 +138,8 @@ nvif_vmm_init(struct nvif_mmu *mmu, s32 oclass, u64 addr, u64 size,
        vmm->limit = args->size;
 
        vmm->page_nr = args->page_nr;
-       vmm->page = kmalloc(sizeof(*vmm->page) * vmm->page_nr, GFP_KERNEL);
+       vmm->page = kmalloc_array(vmm->page_nr, sizeof(*vmm->page),
+                                 GFP_KERNEL);
        if (!vmm->page) {
                ret = -ENOMEM;
                goto done;
index 73e463ed55c3556d1ff0813fbc06cb9b9f694493..dea444d48f944162310fced2d6d25944009c3724 100644 (file)
@@ -73,7 +73,8 @@ nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense)
        }
 
        iccsense->nr_entry = cnt;
-       iccsense->rail = kmalloc(sizeof(struct pwr_rail_t) * cnt, GFP_KERNEL);
+       iccsense->rail = kmalloc_array(cnt, sizeof(struct pwr_rail_t),
+                                      GFP_KERNEL);
        if (!iccsense->rail)
                return -ENOMEM;
 
index 920b3d3478030653cfaf775de433ea1e2cd35552..bbfde1cb3a17cb9cff327e539019a60d7b5d1c40 100644 (file)
@@ -171,7 +171,7 @@ gt215_link_train(struct gt215_ram *ram)
                return -ENOSYS;
 
        /* XXX: Multiple partitions? */
-       result = kmalloc(64 * sizeof(u32), GFP_KERNEL);
+       result = kmalloc_array(64, sizeof(u32), GFP_KERNEL);
        if (!result)
                return -ENOMEM;
 
index 401c02e9e6b2e2b69e3bcaf35e1e390be09dc0b4..f92fe205550bc9c65df236e97be485fbb428ee87 100644 (file)
@@ -940,8 +940,8 @@ int tiler_map_show(struct seq_file *s, void *arg)
        h_adj = omap_dmm->container_height / ydiv;
        w_adj = omap_dmm->container_width / xdiv;
 
-       map = kmalloc(h_adj * sizeof(*map), GFP_KERNEL);
-       global_map = kmalloc((w_adj + 1) * h_adj, GFP_KERNEL);
+       map = kmalloc_array(h_adj, sizeof(*map), GFP_KERNEL);
+       global_map = kmalloc_array(w_adj + 1, h_adj, GFP_KERNEL);
 
        if (!map || !global_map)
                goto error;
index 0faf042b82e187ace34fa66ffb6affe262a684be..3ea716875151c17cb07256c5bf03a439af7e2104 100644 (file)
@@ -244,7 +244,7 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
         * DSS, GPU, etc. are not cache coherent:
         */
        if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) {
-               addrs = kmalloc(npages * sizeof(*addrs), GFP_KERNEL);
+               addrs = kmalloc_array(npages, sizeof(*addrs), GFP_KERNEL);
                if (!addrs) {
                        ret = -ENOMEM;
                        goto free_pages;
index c5716a0ca3b8b2c4afd3b1f60948127bedc90e0a..771250aed78df56bc78b87043eef1620523e0472 100644 (file)
@@ -200,8 +200,8 @@ int qxl_device_init(struct qxl_device *qdev,
                (~(uint64_t)0) >> (qdev->slot_id_bits + qdev->slot_gen_bits);
 
        qdev->mem_slots =
-               kmalloc(qdev->n_mem_slots * sizeof(struct qxl_memslot),
-                       GFP_KERNEL);
+               kmalloc_array(qdev->n_mem_slots, sizeof(struct qxl_memslot),
+                             GFP_KERNEL);
 
        idr_init(&qdev->release_idr);
        spin_lock_init(&qdev->release_idr_lock);
index 2a5b8466d806c2e7a5fe1c3095360f2aca007da0..35dc74883f8373686b95839e8eb7ac750ae78371 100644 (file)
@@ -298,8 +298,9 @@ static int savage_dma_init(drm_savage_private_t * dev_priv)
 
        dev_priv->nr_dma_pages = dev_priv->cmd_dma->size /
            (SAVAGE_DMA_PAGE_SIZE * 4);
-       dev_priv->dma_pages = kmalloc(sizeof(drm_savage_dma_page_t) *
-                                     dev_priv->nr_dma_pages, GFP_KERNEL);
+       dev_priv->dma_pages = kmalloc_array(dev_priv->nr_dma_pages,
+                                           sizeof(drm_savage_dma_page_t),
+                                           GFP_KERNEL);
        if (dev_priv->dma_pages == NULL)
                return -ENOMEM;
 
index 1ee6855212a0f746cf9985f4150e432f10b61db6..50a1d4216ce782ff2327ce7ad043fe3af9ee8092 100644 (file)
@@ -548,7 +548,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,
        DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
                  epd->factored_stage_time);
 
-       buf = kmalloc(fb->width * fb->height, GFP_KERNEL);
+       buf = kmalloc_array(fb->width, fb->height, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
index 06c94e3a5f1521b0759148ede50b85752183e6bc..6e2d1300b457b973e3e6f1e5f072659ed665aaf1 100644 (file)
@@ -348,8 +348,9 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
        if (use_static)
                pages_to_free = static_buf;
        else
-               pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
-                                       GFP_KERNEL);
+               pages_to_free = kmalloc_array(npages_to_free,
+                                             sizeof(struct page *),
+                                             GFP_KERNEL);
        if (!pages_to_free) {
                pr_debug("Failed to allocate memory for pool free operation\n");
                return 0;
@@ -547,7 +548,8 @@ static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags,
        unsigned max_cpages = min(count << order, (unsigned)NUM_PAGES_TO_ALLOC);
 
        /* allocate array for page caching change */
-       caching_array = kmalloc(max_cpages*sizeof(struct page *), GFP_KERNEL);
+       caching_array = kmalloc_array(max_cpages, sizeof(struct page *),
+                                     GFP_KERNEL);
 
        if (!caching_array) {
                pr_debug("Unable to allocate table for new pages\n");
index f63d99c302e44fe2ca5bd9f9ab65e5e89af4c1a8..3f14c1cc078912b65340a58b661d0b96e441718f 100644 (file)
@@ -463,8 +463,9 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
        if (use_static)
                pages_to_free = static_buf;
        else
-               pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
-                                       GFP_KERNEL);
+               pages_to_free = kmalloc_array(npages_to_free,
+                                             sizeof(struct page *),
+                                             GFP_KERNEL);
 
        if (!pages_to_free) {
                pr_debug("%s: Failed to allocate memory for pool free operation\n",
@@ -753,7 +754,8 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,
                        (unsigned)(PAGE_SIZE/sizeof(struct page *)));
 
        /* allocate array for page caching change */
-       caching_array = kmalloc(max_cpages*sizeof(struct page *), GFP_KERNEL);
+       caching_array = kmalloc_array(max_cpages, sizeof(struct page *),
+                                     GFP_KERNEL);
 
        if (!caching_array) {
                pr_debug("%s: Unable to allocate table for new pages\n",
index 71d44c357d3534050d0d2f9a0d7f8751845f1d67..1d34619eb3fe3f57402291e7dbd05c4a193c45e1 100644 (file)
@@ -209,7 +209,7 @@ static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val)
 {
        if (vc4_state->dlist_count == vc4_state->dlist_size) {
                u32 new_size = max(4u, vc4_state->dlist_count * 2);
-               u32 *new_dlist = kmalloc(new_size * 4, GFP_KERNEL);
+               u32 *new_dlist = kmalloc_array(new_size, 4, GFP_KERNEL);
 
                if (!new_dlist)
                        return;
index 355dc7e4956261e3421f27ca4521d7aac1515ad5..f858cc72011d183fa11892fb152e0d9b705c3059 100644 (file)
@@ -134,8 +134,11 @@ static int open_collection(struct hid_parser *parser, unsigned type)
        }
 
        if (parser->device->maxcollection == parser->device->collection_size) {
-               collection = kmalloc(sizeof(struct hid_collection) *
-                               parser->device->collection_size * 2, GFP_KERNEL);
+               collection = kmalloc(
+                               array3_size(sizeof(struct hid_collection),
+                                           parser->device->collection_size,
+                                           2),
+                               GFP_KERNEL);
                if (collection == NULL) {
                        hid_err(parser->device, "failed to reallocate collection array\n");
                        return -ENOMEM;
@@ -1278,7 +1281,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
        __s32 max = field->logical_maximum;
        __s32 *value;
 
-       value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
+       value = kmalloc_array(count, sizeof(__s32), GFP_ATOMIC);
        if (!value)
                return;
 
index 4f4e7a08a07be5c0a37c129905e89d4e03aa10e0..6d99534ac691bb8b09b4cbf399325b2cc932bbc6 100644 (file)
@@ -685,7 +685,7 @@ void hid_dump_report(struct hid_device *hid, int type, u8 *data,
        char *buf;
        unsigned int i;
 
-       buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
+       buf = kmalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
 
        if (!buf)
                return;
index 7f965e2314335857df32bb70c5b9472f7620e96d..864a084b6cbaadf425b1cf653c49c1fb3a9c2c6e 100644 (file)
@@ -394,7 +394,8 @@ static int picolcd_set_par(struct fb_info *info)
                return -EINVAL;
 
        o_fb   = fbdata->bitmap;
-       tmp_fb = kmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel, GFP_KERNEL);
+       tmp_fb = kmalloc_array(PICOLCDFB_SIZE, info->var.bits_per_pixel,
+                              GFP_KERNEL);
        if (!tmp_fb)
                return -ENOMEM;
 
index b39844adea47a333f52079abbefa2ee0186bb13b..4a44e48e08b225a6180ad014604dabc83ce65c2d 100644 (file)
@@ -218,7 +218,7 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
                goto out;
        }
 
-       buf = kmalloc(count * sizeof(__u8), GFP_KERNEL);
+       buf = kmalloc(count, GFP_KERNEL);
        if (!buf) {
                ret = -ENOMEM;
                goto out;
index 1667b6e7674f4a0439befcd544d74753e41d43f3..1aca742fde4aefdf13069324abe7d4a93a0a3006 100644 (file)
@@ -244,7 +244,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
        u8 __user **data_ptrs;
        int i, res;
 
-       data_ptrs = kmalloc(nmsgs * sizeof(u8 __user *), GFP_KERNEL);
+       data_ptrs = kmalloc_array(nmsgs, sizeof(u8 __user *), GFP_KERNEL);
        if (data_ptrs == NULL) {
                kfree(msgs);
                return -ENOMEM;
index 56d7bc228cb31483b71a6a2a7fb2733b915a27e6..416a2f3530711aa556acec93eba46df0ead97a2b 100644 (file)
@@ -985,8 +985,9 @@ static int hwif_init(ide_hwif_t *hwif)
        if (!hwif->sg_max_nents)
                hwif->sg_max_nents = PRD_ENTRIES;
 
-       hwif->sg_table = kmalloc(sizeof(struct scatterlist)*hwif->sg_max_nents,
-                                GFP_KERNEL);
+       hwif->sg_table = kmalloc_array(hwif->sg_max_nents,
+                                      sizeof(struct scatterlist),
+                                      GFP_KERNEL);
        if (!hwif->sg_table) {
                printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name);
                goto out;
index 6813ee717a38e510a406d20fb98cacf75ceb6286..bff10ab141b04fe418cb2f289eb2b12f754fc0ce 100644 (file)
@@ -1855,8 +1855,8 @@ static struct rdma_id_private *cma_new_conn_id(struct rdma_cm_id *listen_id,
 
        rt = &id->route;
        rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1;
-       rt->path_rec = kmalloc(sizeof *rt->path_rec * rt->num_paths,
-                              GFP_KERNEL);
+       rt->path_rec = kmalloc_array(rt->num_paths, sizeof(*rt->path_rec),
+                                    GFP_KERNEL);
        if (!rt->path_rec)
                goto err;
 
index a0a9ed719031b93bd8d04c4c02368cbd9d7dc44a..a077500f7f320316abd690f7e9c2e814821ac6cd 100644 (file)
@@ -235,8 +235,9 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd             *pd,
 
        if (params->cache) {
                pool->cache_bucket =
-                       kmalloc(IB_FMR_HASH_SIZE * sizeof *pool->cache_bucket,
-                               GFP_KERNEL);
+                       kmalloc_array(IB_FMR_HASH_SIZE,
+                                     sizeof(*pool->cache_bucket),
+                                     GFP_KERNEL);
                if (!pool->cache_bucket) {
                        ret = -ENOMEM;
                        goto out_free_pool;
index 5c2cfdea06ad766dbebda9c49792dce27919ceeb..724d23297b355ce02b150663cf6e2ddd5df59885 100644 (file)
@@ -92,8 +92,8 @@ int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num,
                alloc->last = 0;
        alloc->max  = num;
        spin_lock_init(&alloc->lock);
-       alloc->table = kmalloc(BITS_TO_LONGS(num) * sizeof(long),
-                               GFP_KERNEL);
+       alloc->table = kmalloc_array(BITS_TO_LONGS(num), sizeof(long),
+                                    GFP_KERNEL);
        if (!alloc->table)
                return -ENOMEM;
 
index f839bf3b1497a9e1414f9016973822288067765d..4ec519afc45b780812f08ad8acb3fd35f7b16c53 100644 (file)
@@ -302,7 +302,8 @@ static int mlx4_ib_add_gid(const union ib_gid *gid,
                ctx->refcount++;
        }
        if (!ret && hw_update) {
-               gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC);
+               gids = kmalloc_array(MLX4_MAX_PORT_GIDS, sizeof(*gids),
+                                    GFP_ATOMIC);
                if (!gids) {
                        ret = -ENOMEM;
                } else {
@@ -355,7 +356,8 @@ static int mlx4_ib_del_gid(const struct ib_gid_attr *attr, void **context)
        if (!ret && hw_update) {
                int i;
 
-               gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC);
+               gids = kmalloc_array(MLX4_MAX_PORT_GIDS, sizeof(*gids),
+                                    GFP_ATOMIC);
                if (!gids) {
                        ret = -ENOMEM;
                } else {
@@ -2872,9 +2874,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
                        goto err_counter;
 
                ibdev->ib_uc_qpns_bitmap =
-                       kmalloc(BITS_TO_LONGS(ibdev->steer_qpn_count) *
-                               sizeof(long),
-                               GFP_KERNEL);
+                       kmalloc_array(BITS_TO_LONGS(ibdev->steer_qpn_count),
+                                     sizeof(long),
+                                     GFP_KERNEL);
                if (!ibdev->ib_uc_qpns_bitmap)
                        goto err_steer_qp_release;
 
index cd2c08c4533455f94d7a8d82ce6e51ccf83500b9..3b8045fd23ed67634db1541b4a165a5c820b45fc 100644 (file)
@@ -573,8 +573,8 @@ static int alloc_proxy_bufs(struct ib_device *dev, struct mlx4_ib_qp *qp)
        int i;
 
        qp->sqp_proxy_rcv =
-               kmalloc(sizeof (struct mlx4_ib_buf) * qp->rq.wqe_cnt,
-                       GFP_KERNEL);
+               kmalloc_array(qp->rq.wqe_cnt, sizeof(struct mlx4_ib_buf),
+                             GFP_KERNEL);
        if (!qp->sqp_proxy_rcv)
                return -ENOMEM;
        for (i = 0; i < qp->rq.wqe_cnt; i++) {
index b4e0cf4e95cd41ec224c75b72d8ae425d2f83339..aaf10dd5364d44c80b1e9767d0d2a36b8aec0280 100644 (file)
@@ -90,8 +90,8 @@ int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
        alloc->max  = num;
        alloc->mask = mask;
        spin_lock_init(&alloc->lock);
-       alloc->table = kmalloc(BITS_TO_LONGS(num) * sizeof (long),
-                              GFP_KERNEL);
+       alloc->table = kmalloc_array(BITS_TO_LONGS(num), sizeof(long),
+                                    GFP_KERNEL);
        if (!alloc->table)
                return -ENOMEM;
 
@@ -162,7 +162,8 @@ int mthca_array_init(struct mthca_array *array, int nent)
        int npage = (nent * sizeof (void *) + PAGE_SIZE - 1) / PAGE_SIZE;
        int i;
 
-       array->page_list = kmalloc(npage * sizeof *array->page_list, GFP_KERNEL);
+       array->page_list = kmalloc_array(npage, sizeof(*array->page_list),
+                                        GFP_KERNEL);
        if (!array->page_list)
                return -ENOMEM;
 
@@ -220,7 +221,8 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
                        npages *= 2;
                }
 
-               dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
+               dma_list = kmalloc_array(npages, sizeof(*dma_list),
+                                        GFP_KERNEL);
                if (!dma_list)
                        goto err_free;
 
@@ -231,12 +233,14 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
                npages     = (size + PAGE_SIZE - 1) / PAGE_SIZE;
                shift      = PAGE_SHIFT;
 
-               dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
+               dma_list = kmalloc_array(npages, sizeof(*dma_list),
+                                        GFP_KERNEL);
                if (!dma_list)
                        return -ENOMEM;
 
-               buf->page_list = kmalloc(npages * sizeof *buf->page_list,
-                                        GFP_KERNEL);
+               buf->page_list = kmalloc_array(npages,
+                                              sizeof(*buf->page_list),
+                                              GFP_KERNEL);
                if (!buf->page_list)
                        goto err_out;
 
index 419a2a20c0470b72ac95819730dab7e8d92129cd..83aa47eb81a9274110ddb82101c552da32e299d9 100644 (file)
@@ -565,9 +565,9 @@ int mthca_cmd_use_events(struct mthca_dev *dev)
 {
        int i;
 
-       dev->cmd.context = kmalloc(dev->cmd.max_cmds *
-                                  sizeof (struct mthca_cmd_context),
-                                  GFP_KERNEL);
+       dev->cmd.context = kmalloc_array(dev->cmd.max_cmds,
+                                        sizeof(struct mthca_cmd_context),
+                                        GFP_KERNEL);
        if (!dev->cmd.context)
                return -ENOMEM;
 
index 69020173899397ee5889287ee79f0c3525ab8991..30400ea4808b62d1bdd37cc2fcde48b344230f8c 100644 (file)
@@ -479,15 +479,15 @@ static int mthca_create_eq(struct mthca_dev *dev,
        eq->nent = roundup_pow_of_two(max(nent, 2));
        npages = ALIGN(eq->nent * MTHCA_EQ_ENTRY_SIZE, PAGE_SIZE) / PAGE_SIZE;
 
-       eq->page_list = kmalloc(npages * sizeof *eq->page_list,
-                               GFP_KERNEL);
+       eq->page_list = kmalloc_array(npages, sizeof(*eq->page_list),
+                                     GFP_KERNEL);
        if (!eq->page_list)
                goto err_out;
 
        for (i = 0; i < npages; ++i)
                eq->page_list[i].buf = NULL;
 
-       dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
+       dma_list = kmalloc_array(npages, sizeof(*dma_list), GFP_KERNEL);
        if (!dma_list)
                goto err_out_free;
 
index 7a31be3c3e733a26b8e139ccd11a0d56601cc7b6..cc9c0c8ccba3c10154035045bb43f230f8e19009 100644 (file)
@@ -712,9 +712,9 @@ int mthca_init_db_tab(struct mthca_dev *dev)
        dev->db_tab->max_group1 = 0;
        dev->db_tab->min_group2 = dev->db_tab->npages - 1;
 
-       dev->db_tab->page = kmalloc(dev->db_tab->npages *
-                                   sizeof *dev->db_tab->page,
-                                   GFP_KERNEL);
+       dev->db_tab->page = kmalloc_array(dev->db_tab->npages,
+                                         sizeof(*dev->db_tab->page),
+                                         GFP_KERNEL);
        if (!dev->db_tab->page) {
                kfree(dev->db_tab);
                return -ENOMEM;
index ed9a989e501b4f7fa4f42431b696c89ccd972776..dc3c2346045c205e2a8acd0ff4844a924fb161c4 100644 (file)
@@ -153,7 +153,7 @@ static int mthca_buddy_init(struct mthca_buddy *buddy, int max_order)
 
        for (i = 0; i <= buddy->max_order; ++i) {
                s = BITS_TO_LONGS(1 << (buddy->max_order - i));
-               buddy->bits[i] = kmalloc(s * sizeof (long), GFP_KERNEL);
+               buddy->bits[i] = kmalloc_array(s, sizeof(long), GFP_KERNEL);
                if (!buddy->bits[i])
                        goto err_out_free;
                bitmap_zero(buddy->bits[i],
index d21960cd9a49c1f4ad8c5067bc01ba3709f0d073..af1c49d70b899445106df0ff3f0b8107e25415f0 100644 (file)
@@ -1054,8 +1054,8 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
        size = PAGE_ALIGN(qp->send_wqe_offset +
                          (qp->sq.max << qp->sq.wqe_shift));
 
-       qp->wrid = kmalloc((qp->rq.max + qp->sq.max) * sizeof (u64),
-                          GFP_KERNEL);
+       qp->wrid = kmalloc_array(qp->rq.max + qp->sq.max, sizeof(u64),
+                                GFP_KERNEL);
        if (!qp->wrid)
                goto err_out;
 
index d22f970480c0ee7425eee40c87c9fde3112665cb..f79732bc73b4bf95c4d2215fae71a762458462ee 100644 (file)
@@ -155,7 +155,7 @@ static int mthca_alloc_srq_buf(struct mthca_dev *dev, struct mthca_pd *pd,
        if (pd->ibpd.uobject)
                return 0;
 
-       srq->wrid = kmalloc(srq->max * sizeof (u64), GFP_KERNEL);
+       srq->wrid = kmalloc_array(srq->max, sizeof(u64), GFP_KERNEL);
        if (!srq->wrid)
                return -ENOMEM;
 
index 007d5e8a0121eb6485a9666d1e98ee3581b34c0f..61014e2515558241391430cd9b84d11786116ee4 100644 (file)
@@ -904,7 +904,7 @@ static void nes_netdev_set_multicast_list(struct net_device *netdev)
                int i;
                struct netdev_hw_addr *ha;
 
-               addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC);
+               addrs = kmalloc_array(mc_count, ETH_ALEN, GFP_ATOMIC);
                if (!addrs) {
                        set_allmulti(nesdev, nic_active_bit);
                        goto unlock;
index 784ed6b09a469e6526b7049037b248be65786837..eb9f9e9e213bf879a1b857feec3169d34198b69d 100644 (file)
@@ -1873,7 +1873,8 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd,
                srq->bit_fields_len = (srq->rq.max_cnt / 32) +
                    (srq->rq.max_cnt % 32 ? 1 : 0);
                srq->idx_bit_fields =
-                   kmalloc(srq->bit_fields_len * sizeof(u32), GFP_KERNEL);
+                   kmalloc_array(srq->bit_fields_len, sizeof(u32),
+                                 GFP_KERNEL);
                if (srq->idx_bit_fields == NULL)
                        goto arm_err;
                memset(srq->idx_bit_fields, 0xff,
index 8a15e5c7dd912fc8f7d51c51a98a1d9d9ae8870c..fb1ff59f40bd61a3a20e724d45e996be33fb6b0b 100644 (file)
@@ -2496,15 +2496,16 @@ static void init_6120_cntrnames(struct qib_devdata *dd)
                dd->cspec->cntrnamelen = sizeof(cntr6120names) - 1;
        else
                dd->cspec->cntrnamelen = 1 + s - cntr6120names;
-       dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
-               * sizeof(u64), GFP_KERNEL);
+       dd->cspec->cntrs = kmalloc_array(dd->cspec->ncntrs, sizeof(u64),
+                                        GFP_KERNEL);
 
        for (i = 0, s = (char *)portcntr6120names; s; i++)
                s = strchr(s + 1, '\n');
        dd->cspec->nportcntrs = i - 1;
        dd->cspec->portcntrnamelen = sizeof(portcntr6120names) - 1;
-       dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
-               * sizeof(u64), GFP_KERNEL);
+       dd->cspec->portcntrs = kmalloc_array(dd->cspec->nportcntrs,
+                                            sizeof(u64),
+                                            GFP_KERNEL);
 }
 
 static u32 qib_read_6120cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
index bdff2326731e722c9c7fd1d5f4d863bdbdb133e3..163a57a88742891f88748a4ffdf2cfe15a83b38a 100644 (file)
@@ -3147,15 +3147,16 @@ static void init_7220_cntrnames(struct qib_devdata *dd)
                dd->cspec->cntrnamelen = sizeof(cntr7220names) - 1;
        else
                dd->cspec->cntrnamelen = 1 + s - cntr7220names;
-       dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
-               * sizeof(u64), GFP_KERNEL);
+       dd->cspec->cntrs = kmalloc_array(dd->cspec->ncntrs, sizeof(u64),
+                                        GFP_KERNEL);
 
        for (i = 0, s = (char *)portcntr7220names; s; i++)
                s = strchr(s + 1, '\n');
        dd->cspec->nportcntrs = i - 1;
        dd->cspec->portcntrnamelen = sizeof(portcntr7220names) - 1;
-       dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
-               * sizeof(u64), GFP_KERNEL);
+       dd->cspec->portcntrs = kmalloc_array(dd->cspec->nportcntrs,
+                                            sizeof(u64),
+                                            GFP_KERNEL);
 }
 
 static u32 qib_read_7220cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
index 8414ae44a5185b852899d186e701ec3b023b90ae..27155d92f81030ed4b49fa37b0596bb9eba40eaf 100644 (file)
@@ -3648,8 +3648,9 @@ static int qib_do_7322_reset(struct qib_devdata *dd)
 
        if (msix_entries) {
                /* can be up to 512 bytes, too big for stack */
-               msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
-                       sizeof(u64), GFP_KERNEL);
+               msix_vecsave = kmalloc_array(2 * dd->cspec->num_msix_entries,
+                                            sizeof(u64),
+                                            GFP_KERNEL);
        }
 
        /*
@@ -5009,16 +5010,17 @@ static void init_7322_cntrnames(struct qib_devdata *dd)
                dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
        else
                dd->cspec->cntrnamelen = 1 + s - cntr7322names;
-       dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
-               * sizeof(u64), GFP_KERNEL);
+       dd->cspec->cntrs = kmalloc_array(dd->cspec->ncntrs, sizeof(u64),
+                                        GFP_KERNEL);
 
        for (i = 0, s = (char *)portcntr7322names; s; i++)
                s = strchr(s + 1, '\n');
        dd->cspec->nportcntrs = i - 1;
        dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
        for (i = 0; i < dd->num_pports; ++i) {
-               dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
-                       * sizeof(u64), GFP_KERNEL);
+               dd->pport[i].cpspec->portcntrs =
+                       kmalloc_array(dd->cspec->nportcntrs, sizeof(u64),
+                                     GFP_KERNEL);
        }
 }
 
@@ -6412,12 +6414,15 @@ static int qib_init_7322_variables(struct qib_devdata *dd)
        sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
                NUM_VL15_BUFS + BITS_PER_LONG - 1;
        sbufcnt /= BITS_PER_LONG;
-       dd->cspec->sendchkenable = kmalloc(sbufcnt *
-               sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
-       dd->cspec->sendgrhchk = kmalloc(sbufcnt *
-               sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
-       dd->cspec->sendibchk = kmalloc(sbufcnt *
-               sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
+       dd->cspec->sendchkenable =
+               kmalloc_array(sbufcnt, sizeof(*dd->cspec->sendchkenable),
+                             GFP_KERNEL);
+       dd->cspec->sendgrhchk =
+               kmalloc_array(sbufcnt, sizeof(*dd->cspec->sendgrhchk),
+                             GFP_KERNEL);
+       dd->cspec->sendibchk =
+               kmalloc_array(sbufcnt, sizeof(*dd->cspec->sendibchk),
+                             GFP_KERNEL);
        if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
                !dd->cspec->sendibchk) {
                ret = -ENOMEM;
index ca858d6bd37af66e5950bfeac041357506a9dd5b..2f6388596f886c262222ec8feefefca23b83b1db 100644 (file)
@@ -258,8 +258,9 @@ int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
                goto alloc_login_buf_fail;
 
        iser_conn->num_rx_descs = session->cmds_max;
-       iser_conn->rx_descs = kmalloc(iser_conn->num_rx_descs *
-                               sizeof(struct iser_rx_desc), GFP_KERNEL);
+       iser_conn->rx_descs = kmalloc_array(iser_conn->num_rx_descs,
+                                           sizeof(struct iser_rx_desc),
+                                           GFP_KERNEL);
        if (!iser_conn->rx_descs)
                goto rx_desc_alloc_fail;
 
index c35d2cd37d708f23fdc020b9f443553eb54b5db7..9786b24b956fcde94acb16608853341216f018a0 100644 (file)
@@ -1035,16 +1035,17 @@ static int srp_alloc_req_data(struct srp_rdma_ch *ch)
 
        for (i = 0; i < target->req_ring_size; ++i) {
                req = &ch->req_ring[i];
-               mr_list = kmalloc(target->mr_per_cmd * sizeof(void *),
-                                 GFP_KERNEL);
+               mr_list = kmalloc_array(target->mr_per_cmd, sizeof(void *),
+                                       GFP_KERNEL);
                if (!mr_list)
                        goto out;
                if (srp_dev->use_fast_reg) {
                        req->fr_list = mr_list;
                } else {
                        req->fmr_list = mr_list;
-                       req->map_page = kmalloc(srp_dev->max_pages_per_mr *
-                                               sizeof(void *), GFP_KERNEL);
+                       req->map_page = kmalloc_array(srp_dev->max_pages_per_mr,
+                                                     sizeof(void *),
+                                                     GFP_KERNEL);
                        if (!req->map_page)
                                goto out;
                }
index dfec0e1fac29e9f4e85d17dd4cd66347ec5013a3..3081c629a7f79730e319504fd72fa4e92f66debf 100644 (file)
@@ -720,7 +720,7 @@ static struct srpt_ioctx **srpt_alloc_ioctx_ring(struct srpt_device *sdev,
        WARN_ON(ioctx_size != sizeof(struct srpt_recv_ioctx)
                && ioctx_size != sizeof(struct srpt_send_ioctx));
 
-       ring = kmalloc(ring_size * sizeof(ring[0]), GFP_KERNEL);
+       ring = kmalloc_array(ring_size, sizeof(ring[0]), GFP_KERNEL);
        if (!ring)
                goto out;
        for (i = 0; i < ring_size; ++i) {
index d1c6e4846a4acd7ab16307f9bc7b56074e8b58dc..7f4dff9a566ffd1a4c2a51fb10169e698b8aa7ff 100644 (file)
@@ -80,7 +80,7 @@ static int joydump_connect(struct gameport *gameport, struct gameport_driver *dr
 
        timeout = gameport_time(gameport, 10000); /* 10 ms */
 
-       buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
+       buf = kmalloc_array(BUF_SIZE, sizeof(struct joydump), GFP_KERNEL);
        if (!buf) {
                printk(KERN_INFO "joydump: no memory for testing\n");
                goto jd_end;
index 5416f2b2ac21fab0373cb3e88db8d962e15bafd0..4e7ce74e558d66bd2bc689b6eea144a6ce19f6f7 100644 (file)
@@ -3567,8 +3567,8 @@ static void __init acpi_table_parse_srat_its(void)
        if (count <= 0)
                return;
 
-       its_srat_maps = kmalloc(count * sizeof(struct its_srat_map),
-                               GFP_KERNEL);
+       its_srat_maps = kmalloc_array(count, sizeof(struct its_srat_map),
+                                     GFP_KERNEL);
        if (!its_srat_maps) {
                pr_warn("SRAT: Failed to allocate memory for its_srat_maps!\n");
                return;
index 7ac51798949d6c7e186914c5dda586c157c9bd1a..ee510f901720d1686524f37bc598bd6e3ee254a0 100644 (file)
@@ -2268,7 +2268,8 @@ static int capidrv_addcontr(u16 contr, struct capi_profile *profp)
        strcpy(card->name, id);
        card->contrnr = contr;
        card->nbchan = profp->nbchannel;
-       card->bchans = kmalloc(sizeof(capidrv_bchan) * card->nbchan, GFP_ATOMIC);
+       card->bchans = kmalloc_array(card->nbchan, sizeof(capidrv_bchan),
+                                    GFP_ATOMIC);
        if (!card->bchans) {
                printk(KERN_WARNING
                       "capidrv: (%s) Could not allocate bchan-structs.\n", id);
index 56748af78c0425fa248c7954c3f0eb374048f5fb..fd13ed44a54ec0c126f10b8c927a15aba6d2e35f 100644 (file)
@@ -252,7 +252,7 @@ static inline void dump_rawmsg(enum debuglevel level, const char *tag,
                return;
        if (l > 64)
                l = 64; /* arbitrary limit */
-       dbgline = kmalloc(3 * l, GFP_ATOMIC);
+       dbgline = kmalloc_array(3, l, GFP_ATOMIC);
        if (!dbgline)
                return;
        for (i = 0; i < l; i++) {
@@ -272,7 +272,7 @@ static inline void dump_rawmsg(enum debuglevel level, const char *tag,
                        return;
                if (l > 64)
                        l = 64; /* arbitrary limit */
-               dbgline = kmalloc(3 * l, GFP_ATOMIC);
+               dbgline = kmalloc_array(3, l, GFP_ATOMIC);
                if (!dbgline)
                        return;
                data += CAPIMSG_LEN(data);
index 15482c5de33c1958e06d0666f5c3fb12fcbe0ca7..76b5407b5277b60a76150dbe4cbb89211da4e6d9 100644 (file)
@@ -710,7 +710,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
        cs->mode = M_UNKNOWN;
        cs->mstate = MS_UNINITIALIZED;
 
-       cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
+       cs->bcs = kmalloc_array(channels, sizeof(struct bc_state), GFP_KERNEL);
        cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
        if (!cs->bcs || !cs->inbuf) {
                pr_err("out of memory\n");
@@ -1089,7 +1089,7 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
        drv->owner = owner;
        INIT_LIST_HEAD(&drv->list);
 
-       drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
+       drv->cs = kmalloc_array(minors, sizeof(*drv->cs), GFP_KERNEL);
        if (!drv->cs)
                goto error;
 
index 86b82172e9927fbae666ea3f6b04453d45eb7b35..3715fa0343db2aca28368e64c5bd83a19a79dab0 100644 (file)
@@ -1024,7 +1024,7 @@ static unsigned int
        int i;
        unsigned *send;
 
-       if (!(send = kmalloc(cnt * sizeof(unsigned int), GFP_ATOMIC))) {
+       if (!(send = kmalloc_array(cnt, sizeof(unsigned int), GFP_ATOMIC))) {
                printk(KERN_WARNING
                       "HiSax: No memory for hfcd.send\n");
                return (NULL);
index 14dada42874ef7aa709311a5e69f9a526ad5a26b..34d59992839a36abe13151086fb69acc13fe4fd7 100644 (file)
@@ -557,7 +557,8 @@ init_send(struct BCState *bcs)
 {
        int i;
 
-       if (!(bcs->hw.hfc.send = kmalloc(32 * sizeof(unsigned int), GFP_ATOMIC))) {
+       bcs->hw.hfc.send = kmalloc_array(32, sizeof(unsigned int), GFP_ATOMIC);
+       if (!bcs->hw.hfc.send) {
                printk(KERN_WARNING
                       "HiSax: No memory for hfc.send\n");
                return;
index b7f54fa292282c7b3dafc8f5be5763091d5ccf3c..e932a152c405931c05879d00f19cc77060c6edee 100644 (file)
@@ -912,8 +912,10 @@ setstack_tiger(struct PStack *st, struct BCState *bcs)
 void
 inittiger(struct IsdnCardState *cs)
 {
-       if (!(cs->bcs[0].hw.tiger.send = kmalloc(NETJET_DMA_TXSIZE * sizeof(unsigned int),
-                                                GFP_KERNEL | GFP_DMA))) {
+       cs->bcs[0].hw.tiger.send = kmalloc_array(NETJET_DMA_TXSIZE,
+                                                sizeof(unsigned int),
+                                                GFP_KERNEL | GFP_DMA);
+       if (!cs->bcs[0].hw.tiger.send) {
                printk(KERN_WARNING
                       "HiSax: No memory for tiger.send\n");
                return;
@@ -933,8 +935,10 @@ inittiger(struct IsdnCardState *cs)
             cs->hw.njet.base + NETJET_DMA_READ_IRQ);
        outl(virt_to_bus(cs->bcs[0].hw.tiger.s_end),
             cs->hw.njet.base + NETJET_DMA_READ_END);
-       if (!(cs->bcs[0].hw.tiger.rec = kmalloc(NETJET_DMA_RXSIZE * sizeof(unsigned int),
-                                               GFP_KERNEL | GFP_DMA))) {
+       cs->bcs[0].hw.tiger.rec = kmalloc_array(NETJET_DMA_RXSIZE,
+                                               sizeof(unsigned int),
+                                               GFP_KERNEL | GFP_DMA);
+       if (!cs->bcs[0].hw.tiger.rec) {
                printk(KERN_WARNING
                       "HiSax: No memory for tiger.rec\n");
                return;
index 7c6f3f5d9d9a2dc11f7bf2c950b6244b984ef429..1644ac52548bd32410a544f79ce7f586ec0028b1 100644 (file)
@@ -2089,7 +2089,8 @@ isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
                        skb_queue_purge(&d->rpqueue[j]);
                kfree(d->rpqueue);
        }
-       if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
+       d->rpqueue = kmalloc_array(m, sizeof(struct sk_buff_head), GFP_ATOMIC);
+       if (!d->rpqueue) {
                printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
                if (!adding) {
                        kfree(d->rcvcount);
@@ -2103,7 +2104,8 @@ isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
 
        if ((adding) && (d->rcv_waitq))
                kfree(d->rcv_waitq);
-       d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
+       d->rcv_waitq = kmalloc(array3_size(sizeof(wait_queue_head_t), 2, m),
+                              GFP_ATOMIC);
        if (!d->rcv_waitq) {
                printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
                if (!adding) {
index 491df0fa0835ed3cb6c8519234826284bc129f96..f497a77423a2b7c65dbc2150555b9658e6e8d863 100644 (file)
@@ -833,8 +833,8 @@ static int pblk_alloc_line_meta(struct pblk *pblk, struct pblk_line *line)
                goto free_blk_bitmap;
 
 
-       line->chks = kmalloc(lm->blk_per_line * sizeof(struct nvm_chk_meta),
-                                                               GFP_KERNEL);
+       line->chks = kmalloc_array(lm->blk_per_line,
+                                  sizeof(struct nvm_chk_meta), GFP_KERNEL);
        if (!line->chks)
                goto free_erase_bitmap;
 
index fc68c7aaef8ed0d19d903c27a676c4d373aec279..136e7e66d870f86d79f3b18bb69955339abe3947 100644 (file)
@@ -2743,7 +2743,8 @@ static int create_journal(struct dm_integrity_c *ic, char **error)
                                        r = -ENOMEM;
                                        goto bad;
                                }
-                               section_req->iv = kmalloc(ivsize * 2, GFP_KERNEL);
+                               section_req->iv = kmalloc_array(ivsize, 2,
+                                                               GFP_KERNEL);
                                if (!section_req->iv) {
                                        skcipher_request_free(section_req);
                                        *error = "Unable to allocate iv";
index f745404da72133681ed7c025a41ce05fae1f0859..97de7a7334d4c59a0e051372b57e8538b9182e5a 100644 (file)
@@ -326,8 +326,8 @@ static int init_origin_hash(void)
 {
        int i;
 
-       _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
-                          GFP_KERNEL);
+       _origins = kmalloc_array(ORIGIN_HASH_SIZE, sizeof(struct list_head),
+                                GFP_KERNEL);
        if (!_origins) {
                DMERR("unable to allocate memory for _origins");
                return -ENOMEM;
@@ -335,8 +335,9 @@ static int init_origin_hash(void)
        for (i = 0; i < ORIGIN_HASH_SIZE; i++)
                INIT_LIST_HEAD(_origins + i);
 
-       _dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
-                             GFP_KERNEL);
+       _dm_origins = kmalloc_array(ORIGIN_HASH_SIZE,
+                                   sizeof(struct list_head),
+                                   GFP_KERNEL);
        if (!_dm_origins) {
                DMERR("unable to allocate memory for _dm_origins");
                kfree(_origins);
index 56059fb56e2d255a0e635fdf56f9c6edfa20f0df..21de30b4e2a16051490ce5a2548c3711a3f0284e 100644 (file)
@@ -915,7 +915,9 @@ static int parse_histogram(const char *h, unsigned *n_histogram_entries,
                if (*q == ',')
                        (*n_histogram_entries)++;
 
-       *histogram_boundaries = kmalloc(*n_histogram_entries * sizeof(unsigned long long), GFP_KERNEL);
+       *histogram_boundaries = kmalloc_array(*n_histogram_entries,
+                                             sizeof(unsigned long long),
+                                             GFP_KERNEL);
        if (!*histogram_boundaries)
                return -ENOMEM;
 
index caa51dd351b668cef9735b1f64f317faa126ff26..938766794c2ef3b6caf538a0fa787447eadb160c 100644 (file)
@@ -561,7 +561,7 @@ static char **realloc_argv(unsigned *size, char **old_argv)
                new_size = 8;
                gfp = GFP_NOIO;
        }
-       argv = kmalloc(new_size * sizeof(*argv), gfp);
+       argv = kmalloc_array(new_size, sizeof(*argv), gfp);
        if (argv) {
                memcpy(argv, old_argv, *size * sizeof(*argv));
                *size = new_size;
index 239c7bb3929ba0ac58df67ae9b213ceb62cd7d41..01c8329b512d2ca8ce119a0b835edb738f22d9e7 100644 (file)
@@ -789,8 +789,8 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
        num_pages = DIV_ROUND_UP(bytes, PAGE_SIZE);
        offset = slot_number * num_pages;
 
-       store->filemap = kmalloc(sizeof(struct page *)
-                                * num_pages, GFP_KERNEL);
+       store->filemap = kmalloc_array(num_pages, sizeof(struct page *),
+                                      GFP_KERNEL);
        if (!store->filemap)
                return -ENOMEM;
 
index 0b344d0875814e9ba2a78badb4c8eeabad566bda..e7c0ecd1923450524dad48fede345cfcb455eb57 100644 (file)
@@ -126,8 +126,8 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
        if (!r1_bio)
                return NULL;
 
-       rps = kmalloc(sizeof(struct resync_pages) * pi->raid_disks,
-                     gfp_flags);
+       rps = kmalloc_array(pi->raid_disks, sizeof(struct resync_pages),
+                           gfp_flags);
        if (!rps)
                goto out_free_r1bio;
 
index 1147ae59e3b6e063ad62e4cf90e57cb92b581dd0..e35db73b9b9e92d14c91c520deeb8cc1a6f76024 100644 (file)
@@ -175,7 +175,7 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
                nalloc_rp = nalloc;
        else
                nalloc_rp = nalloc * 2;
-       rps = kmalloc(sizeof(struct resync_pages) * nalloc_rp, gfp_flags);
+       rps = kmalloc_array(nalloc_rp, sizeof(struct resync_pages), gfp_flags);
        if (!rps)
                goto out_free_r10bio;
 
index 6a6be0b49f7013e18b696c6e11eec295b90e29e0..74aff6877d9cd860b123109a80943c5ea7187d89 100644 (file)
@@ -256,7 +256,8 @@ bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
        u32 addr;
 
        /* skip list for window clipping */
-       if (NULL == (skips = kmalloc(sizeof(*skips) * ov->nclips,GFP_KERNEL)))
+       skips = kmalloc_array(ov->nclips, sizeof(*skips),GFP_KERNEL);
+       if (NULL == skips)
                return -ENOMEM;
 
        /* estimate risc mem: worst case is (1.5*clip+1) * lines instructions
index 8e62b8be6529d5f5becb88aefb91b7ea7fa18678..b19058e36853deac8bb5d2d0b17c88eb8416edb3 100644 (file)
@@ -1077,7 +1077,7 @@ static int ivtvfb_init_vidmode(struct ivtv *itv)
 
        /* Allocate the pseudo palette */
        oi->ivtvfb_info.pseudo_palette =
-               kmalloc(sizeof(u32) * 16, GFP_KERNEL|__GFP_NOWARN);
+               kmalloc_array(16, sizeof(u32), GFP_KERNEL|__GFP_NOWARN);
 
        if (!oi->ivtvfb_info.pseudo_palette) {
                IVTVFB_ERR("abort, unable to alloc pseudo palette\n");
index 82ec216f2ad8233ac482f9eeb895a4b7101a5a7a..59031018985eb1cbf1c2fee0f66c45a3f6155096 100644 (file)
@@ -859,8 +859,9 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
        /* create a string array containing the names of all the preset timings */
        while (v4l2_dv_timings_presets[dev->query_dv_timings_size].bt.width)
                dev->query_dv_timings_size++;
-       dev->query_dv_timings_qmenu = kmalloc(dev->query_dv_timings_size *
-                                          (sizeof(void *) + 32), GFP_KERNEL);
+       dev->query_dv_timings_qmenu = kmalloc_array(dev->query_dv_timings_size,
+                                                   (sizeof(void *) + 32),
+                                                   GFP_KERNEL);
        if (dev->query_dv_timings_qmenu == NULL)
                goto free_dev;
        for (i = 0; i < dev->query_dv_timings_size; i++) {
index b51fc372ca25b52a11776fb7e7321905360c0e0d..a771e0a52610c84e492f1bafccfebbfe9f73e7c5 100644 (file)
@@ -663,7 +663,8 @@ static int submit_urbs(struct camera_data *cam)
                if (cam->sbuf[i].data)
                        continue;
                cam->sbuf[i].data =
-                   kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
+                   kmalloc_array(FRAME_SIZE_PER_DESC, FRAMES_PER_DESC,
+                                 GFP_KERNEL);
                if (!cam->sbuf[i].data) {
                        while (--i >= 0) {
                                kfree(cam->sbuf[i].data);
index d96236d786d1819e6c3eb0d62d7c6614203b584a..c4a84fb930b63a2c7dab59831d3df6ddded4a99e 100644 (file)
@@ -710,7 +710,7 @@ static int cx231xx_audio_init(struct cx231xx *dev)
        dev_info(dev->dev,
                "audio EndPoint Addr 0x%x, Alternate settings: %i\n",
                adev->end_point_addr, adev->num_alt);
-       adev->alt_max_pkt_size = kmalloc(32 * adev->num_alt, GFP_KERNEL);
+       adev->alt_max_pkt_size = kmalloc_array(32, adev->num_alt, GFP_KERNEL);
        if (!adev->alt_max_pkt_size) {
                err = -ENOMEM;
                goto err_free_card;
index ed9bcaf08d5ec46df4b4b21af8fcaefd460dc47f..19c6a0354ce000fa848b4ac154f0a731cd8b6b9c 100644 (file)
@@ -1143,7 +1143,8 @@ static int go7007_usb_probe(struct usb_interface *intf,
        usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
        if (usb->intr_urb == NULL)
                goto allocfail;
-       usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
+       usb->intr_urb->transfer_buffer = kmalloc_array(2, sizeof(u16),
+                                                      GFP_KERNEL);
        if (usb->intr_urb->transfer_buffer == NULL)
                goto allocfail;
 
index 0ae557cd15efb2f32170b6348782cbb5653c2c42..445782919446166d4d8ed525952a5c957996568b 100644 (file)
@@ -363,7 +363,7 @@ static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
        if (len * 2 <= USB_BUF_SZ) {
                p = tmpbuf = gspca_dev->usb_buf;
        } else {
-               p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
+               p = tmpbuf = kmalloc_array(len, 2, GFP_KERNEL);
                if (!tmpbuf) {
                        pr_err("Out of memory\n");
                        return;
index 72bd893c965920e20f1de2e1b9f88a01101f2aca..468f5ccf4ae6c98ad089614a596d62b0508a130b 100644 (file)
@@ -290,8 +290,9 @@ static int stk1160_probe(struct usb_interface *interface,
                return -ENODEV;
 
        /* Alloc an array for all possible max_pkt_size */
-       alt_max_pkt_size = kmalloc(sizeof(alt_max_pkt_size[0]) *
-                       interface->num_altsetting, GFP_KERNEL);
+       alt_max_pkt_size = kmalloc_array(interface->num_altsetting,
+                                        sizeof(alt_max_pkt_size[0]),
+                                        GFP_KERNEL);
        if (alt_max_pkt_size == NULL)
                return -ENOMEM;
 
index aa85fe31c8353c2a0953808c0a276ff580804a61..96055de6e8ce2815cde4c0087c651f1a0857dd01 100644 (file)
@@ -463,11 +463,12 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
        if (dev->urb_buffer)
                return 0;
 
-       dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
+       dev->urb_buffer = kmalloc_array(num_bufs, sizeof(void *), GFP_KERNEL);
        if (!dev->urb_buffer)
                return -ENOMEM;
 
-       dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
+       dev->urb_dma = kmalloc_array(num_bufs, sizeof(dma_addr_t *),
+                                    GFP_KERNEL);
        if (!dev->urb_dma)
                return -ENOMEM;
 
@@ -583,12 +584,14 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
 
        dev->isoc_ctl.num_bufs = num_bufs;
 
-       dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
+       dev->isoc_ctl.urb = kmalloc_array(num_bufs, sizeof(void *),
+                                         GFP_KERNEL);
        if (!dev->isoc_ctl.urb)
                return -ENOMEM;
 
-       dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
-                                  GFP_KERNEL);
+       dev->isoc_ctl.transfer_buffer = kmalloc_array(num_bufs,
+                                                     sizeof(void *),
+                                                     GFP_KERNEL);
        if (!dev->isoc_ctl.transfer_buffer) {
                kfree(dev->isoc_ctl.urb);
                return -ENOMEM;
index 0f5954a1fea25a1e55beef6abaa6c35f18a5fc7b..f29d1bef029367f241dbbb1125199ee2d99f2525 100644 (file)
@@ -1492,7 +1492,8 @@ static int usbvision_probe(struct usb_interface *intf,
 
        usbvision->num_alt = uif->num_altsetting;
        PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
-       usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
+       usbvision->alt_max_pkt_size = kmalloc_array(32, usbvision->num_alt,
+                                                   GFP_KERNEL);
        if (!usbvision->alt_max_pkt_size) {
                ret = -ENOMEM;
                goto err_pkt;
index b28c997a7ab0b67157725393b75ce0abb3c15555..a88b2e51a666cb0f1aa649506addb730ceef9805 100644 (file)
@@ -513,8 +513,8 @@ static int uvc_video_clock_init(struct uvc_streaming *stream)
        spin_lock_init(&clock->lock);
        clock->size = 32;
 
-       clock->samples = kmalloc(clock->size * sizeof(*clock->samples),
-                                GFP_KERNEL);
+       clock->samples = kmalloc_array(clock->size, sizeof(*clock->samples),
+                                      GFP_KERNEL);
        if (clock->samples == NULL)
                return -ENOMEM;
 
index 2e5c346f9c303ce27bf53298672135127e08dff3..78155f596f7460769a9997cbcf9303cc3daeaf09 100644 (file)
@@ -175,7 +175,8 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
        dma->offset = data & ~PAGE_MASK;
        dma->size = size;
        dma->nr_pages = last-first+1;
-       dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
+       dma->pages = kmalloc_array(dma->nr_pages, sizeof(struct page *),
+                                  GFP_KERNEL);
        if (NULL == dma->pages)
                return -ENOMEM;
 
index a15181fa45f7a7816e29ae961668454564f6a8bd..716fc8ed31d324dc4daa8ad83d730217ae5457f0 100644 (file)
@@ -1201,7 +1201,8 @@ static int msb_read_boot_blocks(struct msb_data *msb)
        dbg_verbose("Start of a scan for the boot blocks");
 
        if (!msb->boot_page) {
-               page = kmalloc(sizeof(struct ms_boot_page)*2, GFP_KERNEL);
+               page = kmalloc_array(2, sizeof(struct ms_boot_page),
+                                    GFP_KERNEL);
                if (!page)
                        return -ENOMEM;
 
@@ -1341,7 +1342,8 @@ static int msb_ftl_initialize(struct msb_data *msb)
        msb->used_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL);
        msb->erased_blocks_bitmap = kzalloc(msb->block_count / 8, GFP_KERNEL);
        msb->lba_to_pba_table =
-               kmalloc(msb->logical_block_count * sizeof(u16), GFP_KERNEL);
+               kmalloc_array(msb->logical_block_count, sizeof(u16),
+                             GFP_KERNEL);
 
        if (!msb->used_blocks_bitmap || !msb->lba_to_pba_table ||
                                                !msb->erased_blocks_bitmap) {
index 4cbed4d06aa7d9d30726d324cef1dcf532bf1a17..ebc00d47abf5243dee30ec4266e0726836b88883 100644 (file)
@@ -394,7 +394,8 @@ mpt_lan_open(struct net_device *dev)
                                "a moment.\n");
        }
 
-       priv->mpt_txfidx = kmalloc(priv->tx_max_out * sizeof(int), GFP_KERNEL);
+       priv->mpt_txfidx = kmalloc_array(priv->tx_max_out, sizeof(int),
+                                        GFP_KERNEL);
        if (priv->mpt_txfidx == NULL)
                goto out;
        priv->mpt_txfidx_tail = -1;
@@ -408,8 +409,8 @@ mpt_lan_open(struct net_device *dev)
 
        dlprintk((KERN_INFO MYNAM "@lo: Finished initializing SendCtl\n"));
 
-       priv->mpt_rxfidx = kmalloc(priv->max_buckets_out * sizeof(int),
-                                  GFP_KERNEL);
+       priv->mpt_rxfidx = kmalloc_array(priv->max_buckets_out, sizeof(int),
+                                        GFP_KERNEL);
        if (priv->mpt_rxfidx == NULL)
                goto out_SendCtl;
        priv->mpt_rxfidx_tail = -1;
index 34a5a41578d719a04c5bcf317da0d101cd2f2531..59dc24bb70eca2d357db7dd3a1198a6f6a18f04a 100644 (file)
@@ -964,7 +964,7 @@ static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf,
        if (colon_ch != NULL) {
                csraddr_len = colon_ch - buf;
                csraddr_str =
-                       kmalloc(sizeof(char)*(csraddr_len + 1), GFP_KERNEL);
+                       kmalloc(csraddr_len + 1, GFP_KERNEL);
                if (csraddr_str == NULL) {
                        ret = -ENOMEM;
                        goto free_buf;
index 0339538c182d20ea6489407e505aff66b0dfec79..b4d7774cfe073c8651825d43e909fb7d974b390b 100644 (file)
@@ -449,12 +449,14 @@ static int qp_alloc_ppn_set(void *prod_q,
                return VMCI_ERROR_ALREADY_EXISTS;
 
        produce_ppns =
-           kmalloc(num_produce_pages * sizeof(*produce_ppns), GFP_KERNEL);
+           kmalloc_array(num_produce_pages, sizeof(*produce_ppns),
+                         GFP_KERNEL);
        if (!produce_ppns)
                return VMCI_ERROR_NO_MEM;
 
        consume_ppns =
-           kmalloc(num_consume_pages * sizeof(*consume_ppns), GFP_KERNEL);
+           kmalloc_array(num_consume_pages, sizeof(*consume_ppns),
+                         GFP_KERNEL);
        if (!consume_ppns) {
                kfree(produce_ppns);
                return VMCI_ERROR_NO_MEM;
index f5695be14499855a2a54071004e8107c3289f680..5a81bd8073bcf553002e4f748511a829e65961a1 100644 (file)
@@ -758,7 +758,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
                newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
                if (!newcfi)
                        return -ENOMEM;
-               shared = kmalloc(sizeof(struct flchip_shared) * cfi->numchips, GFP_KERNEL);
+               shared = kmalloc_array(cfi->numchips,
+                                      sizeof(struct flchip_shared),
+                                      GFP_KERNEL);
                if (!shared) {
                        kfree(newcfi);
                        return -ENOMEM;
index 7c889eca9ab0b1288270e2a7efaa50e7da7138a5..22506d22194e17404171b6aebd0d123e4649cfff 100644 (file)
@@ -692,8 +692,9 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
        mtd->size = devsize * cfi->numchips;
 
        mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
-       mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
-                                   * mtd->numeraseregions, GFP_KERNEL);
+       mtd->eraseregions = kmalloc_array(mtd->numeraseregions,
+                                         sizeof(struct mtd_erase_region_info),
+                                         GFP_KERNEL);
        if (!mtd->eraseregions)
                goto setup_err;
 
index 7b7658a05036d59c46ea7ca8e5db9322e59792aa..35aa72b720a6246871325250242b99485ed70d7b 100644 (file)
@@ -184,8 +184,9 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
        mtd->size = devsize * cfi->numchips;
 
        mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
-       mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
-                       * mtd->numeraseregions, GFP_KERNEL);
+       mtd->eraseregions = kmalloc_array(mtd->numeraseregions,
+                                         sizeof(struct mtd_erase_region_info),
+                                         GFP_KERNEL);
        if (!mtd->eraseregions) {
                kfree(cfi->cmdset_priv);
                kfree(mtd);
index ef6ad2551d574c5037767b1ff9fdf37300f3490c..1f8063c6aed1633ca5dbc3c8ae061c14fe808827 100644 (file)
@@ -201,15 +201,16 @@ static int build_maps(partition_t *part)
     /* Set up erase unit maps */
     part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) -
        part->header.NumTransferUnits;
-    part->EUNInfo = kmalloc(part->DataUnits * sizeof(struct eun_info_t),
-                           GFP_KERNEL);
+    part->EUNInfo = kmalloc_array(part->DataUnits, sizeof(struct eun_info_t),
+                                  GFP_KERNEL);
     if (!part->EUNInfo)
            goto out;
     for (i = 0; i < part->DataUnits; i++)
        part->EUNInfo[i].Offset = 0xffffffff;
     part->XferInfo =
-       kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t),
-               GFP_KERNEL);
+       kmalloc_array(part->header.NumTransferUnits,
+                      sizeof(struct xfer_info_t),
+                      GFP_KERNEL);
     if (!part->XferInfo)
            goto out_EUNInfo;
 
@@ -269,8 +270,8 @@ static int build_maps(partition_t *part)
     memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t));
     part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize;
 
-    part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(uint32_t),
-                             GFP_KERNEL);
+    part->bam_cache = kmalloc_array(part->BlocksPerUnit, sizeof(uint32_t),
+                                    GFP_KERNEL);
     if (!part->bam_cache)
            goto out_VirtualBlockMap;
 
index 2d598412972dcd3f6350fae3d9c9b8481811824b..10d977e9709d5cb01b2150a1480f77c60ea32f96 100644 (file)
@@ -270,7 +270,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
                inftl->nb_blocks = ip->lastUnit + 1;
 
                /* Memory alloc */
-               inftl->PUtable = kmalloc(inftl->nb_blocks * sizeof(u16), GFP_KERNEL);
+               inftl->PUtable = kmalloc_array(inftl->nb_blocks, sizeof(u16),
+                                              GFP_KERNEL);
                if (!inftl->PUtable) {
                        printk(KERN_WARNING "INFTL: allocation of PUtable "
                                "failed (%zd bytes)\n",
@@ -278,7 +279,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
                        return -ENOMEM;
                }
 
-               inftl->VUtable = kmalloc(inftl->nb_blocks * sizeof(u16), GFP_KERNEL);
+               inftl->VUtable = kmalloc_array(inftl->nb_blocks, sizeof(u16),
+                                              GFP_KERNEL);
                if (!inftl->VUtable) {
                        kfree(inftl->PUtable);
                        printk(KERN_WARNING "INFTL: allocation of VUtable "
index 5c5ba3c7c79d5ffa8a1d545e68fec32feae291dd..b13557fe52bd0b3d4589eeb7ae7c890bf69eca77 100644 (file)
@@ -78,7 +78,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
        mtd->erasesize = 1 << lpddr->qinfo->UniformBlockSizeShift;
        mtd->writesize = 1 << lpddr->qinfo->BufSizeShift;
 
-       shared = kmalloc(sizeof(struct flchip_shared) * lpddr->numchips,
+       shared = kmalloc_array(lpddr->numchips, sizeof(struct flchip_shared),
                                                GFP_KERNEL);
        if (!shared) {
                kfree(lpddr);
index 6b223cfe92b7ac0e789a03364648744dd4a136fd..c5d4b6589488c10dd59496b3d214a7cff66b2eeb 100644 (file)
@@ -629,15 +629,15 @@ static int vmu_connect(struct maple_device *mdev)
        * Not sure there are actually any multi-partition devices in the
        * real world, but the hardware supports them, so, so will we
        */
-       card->parts = kmalloc(sizeof(struct vmupart) * card->partitions,
-               GFP_KERNEL);
+       card->parts = kmalloc_array(card->partitions, sizeof(struct vmupart),
+                                   GFP_KERNEL);
        if (!card->parts) {
                error = -ENOMEM;
                goto fail_partitions;
        }
 
-       card->mtd = kmalloc(sizeof(struct mtd_info) * card->partitions,
-               GFP_KERNEL);
+       card->mtd = kmalloc_array(card->partitions, sizeof(struct mtd_info),
+                                 GFP_KERNEL);
        if (!card->mtd) {
                error = -ENOMEM;
                goto fail_mtd_info;
index 6b86d1a73cf2bb73084e4a8def0feb8ae79400e7..cbc5925e6440746f7ad158bb6b24daf4a3e0267d 100644 (file)
@@ -778,8 +778,9 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],       /* subdevices to c
                concat->mtd.erasesize = max_erasesize;
                concat->mtd.numeraseregions = num_erase_region;
                concat->mtd.eraseregions = erase_region_p =
-                   kmalloc(num_erase_region *
-                           sizeof (struct mtd_erase_region_info), GFP_KERNEL);
+                   kmalloc_array(num_erase_region,
+                                 sizeof(struct mtd_erase_region_info),
+                                 GFP_KERNEL);
                if (!erase_region_p) {
                        kfree(concat);
                        printk
index 7161f8a17f6204b59412eb7a04604993990f58d4..6593879595e397b802e8dab5930a0cadb8f93483 100644 (file)
@@ -1340,7 +1340,7 @@ static int mtdswap_init(struct mtdswap_dev *d, unsigned int eblocks,
        if (!d->page_buf)
                goto page_buf_fail;
 
-       d->oob_buf = kmalloc(2 * mtd->oobavail, GFP_KERNEL);
+       d->oob_buf = kmalloc_array(2, mtd->oobavail, GFP_KERNEL);
        if (!d->oob_buf)
                goto oob_buf_fail;
 
index 7f11b68f6db15e92fa4627f379d4504d7a2284ab..b7387ace567a4b249b14ad2ae5f28a2db53e442f 100644 (file)
@@ -186,7 +186,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
        }
 
        nbc->eccmask = kmalloc(eccbytes, GFP_KERNEL);
-       nbc->errloc = kmalloc(t*sizeof(*nbc->errloc), GFP_KERNEL);
+       nbc->errloc = kmalloc_array(t, sizeof(*nbc->errloc), GFP_KERNEL);
        if (!nbc->eccmask || !nbc->errloc)
                goto fail;
        /*
index 6281da3dadaca4a8b50cd4da57ec060b381b9b6e..27184e3874dbbd7775e7a40691c4e4f54409fc6f 100644 (file)
@@ -199,13 +199,16 @@ device is already correct.
                nftl->lastEUN = nftl->nb_blocks - 1;
 
                /* memory alloc */
-               nftl->EUNtable = kmalloc(nftl->nb_blocks * sizeof(u16), GFP_KERNEL);
+               nftl->EUNtable = kmalloc_array(nftl->nb_blocks, sizeof(u16),
+                                              GFP_KERNEL);
                if (!nftl->EUNtable) {
                        printk(KERN_NOTICE "NFTL: allocation of EUNtable failed\n");
                        return -ENOMEM;
                }
 
-               nftl->ReplUnitTable = kmalloc(nftl->nb_blocks * sizeof(u16), GFP_KERNEL);
+               nftl->ReplUnitTable = kmalloc_array(nftl->nb_blocks,
+                                                   sizeof(u16),
+                                                   GFP_KERNEL);
                if (!nftl->ReplUnitTable) {
                        kfree(nftl->EUNtable);
                        printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n");
index 79636349df965a4c67c1db5feeb2ac3f159bbdeb..9d019ce1589eee317c95b351ed588f294da4d817 100644 (file)
@@ -750,7 +750,7 @@ static int sm_init_zone(struct sm_ftl *ftl, int zone_num)
        dbg("initializing zone %d", zone_num);
 
        /* Allocate memory for FTL table */
-       zone->lba_to_phys_table = kmalloc(ftl->max_lba * 2, GFP_KERNEL);
+       zone->lba_to_phys_table = kmalloc_array(ftl->max_lba, 2, GFP_KERNEL);
 
        if (!zone->lba_to_phys_table)
                return -ENOMEM;
index 95f0bf95f09577702f16d49383fb119647e579ca..7a1e54546f4aa839a5822a75eddd4d43c9d5a01e 100644 (file)
@@ -332,8 +332,9 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
                                (long)ssfdc->sectors;
 
        /* Allocate logical block map */
-       ssfdc->logic_block_map = kmalloc(sizeof(ssfdc->logic_block_map[0]) *
-                                        ssfdc->map_len, GFP_KERNEL);
+       ssfdc->logic_block_map =
+               kmalloc_array(ssfdc->map_len,
+                             sizeof(ssfdc->logic_block_map[0]), GFP_KERNEL);
        if (!ssfdc->logic_block_map)
                goto out_err;
        memset(ssfdc->logic_block_map, 0xff, sizeof(ssfdc->logic_block_map[0]) *
index e509f8aa9a7eea21db08004a8eca1608880ac7d1..0fe1217f94b937a76f4fdf5842642e761ea95eb4 100644 (file)
@@ -199,7 +199,7 @@ static int __init mtd_stresstest_init(void)
        err = -ENOMEM;
        readbuf = vmalloc(bufsize);
        writebuf = vmalloc(bufsize);
-       offsets = kmalloc(ebcnt * sizeof(int), GFP_KERNEL);
+       offsets = kmalloc_array(ebcnt, sizeof(int), GFP_KERNEL);
        if (!readbuf || !writebuf || !offsets)
                goto out;
        for (i = 0; i < ebcnt; i++)
index edb1c8362faa1d910fe6ca742ab5a84efb78474f..b98481b69314d94d3a1f205ba804491d3235638c 100644 (file)
@@ -1536,11 +1536,11 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
 
        num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT;
 
-       scan_eba = kmalloc(sizeof(*scan_eba) * num_volumes, GFP_KERNEL);
+       scan_eba = kmalloc_array(num_volumes, sizeof(*scan_eba), GFP_KERNEL);
        if (!scan_eba)
                return -ENOMEM;
 
-       fm_eba = kmalloc(sizeof(*fm_eba) * num_volumes, GFP_KERNEL);
+       fm_eba = kmalloc_array(num_volumes, sizeof(*fm_eba), GFP_KERNEL);
        if (!fm_eba) {
                kfree(scan_eba);
                return -ENOMEM;
@@ -1551,15 +1551,17 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
                if (!vol)
                        continue;
 
-               scan_eba[i] = kmalloc(vol->reserved_pebs * sizeof(**scan_eba),
-                                     GFP_KERNEL);
+               scan_eba[i] = kmalloc_array(vol->reserved_pebs,
+                                           sizeof(**scan_eba),
+                                           GFP_KERNEL);
                if (!scan_eba[i]) {
                        ret = -ENOMEM;
                        goto out_free;
                }
 
-               fm_eba[i] = kmalloc(vol->reserved_pebs * sizeof(**fm_eba),
-                                   GFP_KERNEL);
+               fm_eba[i] = kmalloc_array(vol->reserved_pebs,
+                                         sizeof(**fm_eba),
+                                         GFP_KERNEL);
                if (!fm_eba[i]) {
                        ret = -ENOMEM;
                        goto out_free;
index 12a6a93d221bb85a30af80741d18c89c85412cc5..b56d84c7df46e2a2b985263b32dc54132ad27b2d 100644 (file)
@@ -551,13 +551,13 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
        if (lance_debug > 6) printk(" (#0x%05lx)", (unsigned long)lp);
        dev->ml_priv = lp;
        lp->name = chipname;
-       lp->rx_buffs = (unsigned long)kmalloc(PKT_BUF_SZ*RX_RING_SIZE,
-                                                 GFP_DMA | GFP_KERNEL);
+       lp->rx_buffs = (unsigned long)kmalloc_array(RX_RING_SIZE, PKT_BUF_SZ,
+                                                   GFP_DMA | GFP_KERNEL);
        if (!lp->rx_buffs)
                goto out_lp;
        if (lance_need_isa_bounce_buffers) {
-               lp->tx_bounce_buffs = kmalloc(PKT_BUF_SZ*TX_RING_SIZE,
-                                                 GFP_DMA | GFP_KERNEL);
+               lp->tx_bounce_buffs = kmalloc_array(TX_RING_SIZE, PKT_BUF_SZ,
+                                                   GFP_DMA | GFP_KERNEL);
                if (!lp->tx_bounce_buffs)
                        goto out_rx;
        } else
index cfe86a20c899dd3bf58e5780e138b9bd7056daf5..28e9ae1a193b40405a80e60abc6ccd2f1d8e1bc8 100644 (file)
@@ -209,8 +209,8 @@ static int atl1c_get_eeprom(struct net_device *netdev,
        first_dword = eeprom->offset >> 2;
        last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
 
-       eeprom_buff = kmalloc(sizeof(u32) *
-                       (last_dword - first_dword + 1), GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32),
+                                   GFP_KERNEL);
        if (eeprom_buff == NULL)
                return -ENOMEM;
 
index cb489e7e8374b5247cf1d431903b04ea81f2474a..282ebdde47699789404c2848124de1386ec50f5a 100644 (file)
@@ -236,8 +236,8 @@ static int atl1e_get_eeprom(struct net_device *netdev,
        first_dword = eeprom->offset >> 2;
        last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
 
-       eeprom_buff = kmalloc(sizeof(u32) *
-                       (last_dword - first_dword + 1), GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32),
+                                   GFP_KERNEL);
        if (eeprom_buff == NULL)
                return -ENOMEM;
 
index db4bcc51023adf546ed0e8a9c8d075beec048faf..bb41becb66099389216192c761541ad1fd51790d 100644 (file)
@@ -1941,8 +1941,8 @@ static int atl2_get_eeprom(struct net_device *netdev,
        first_dword = eeprom->offset >> 2;
        last_dword = (eeprom->offset + eeprom->len - 1) >> 2;
 
-       eeprom_buff = kmalloc(sizeof(u32) * (last_dword - first_dword + 1),
-               GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_dword - first_dword + 1, sizeof(u32),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index 3853296d78c14e3d5645fb0597948fe8e11851f5..e13bf3b4636d5c11e612b5e9a51691942d161977 100644 (file)
@@ -2666,7 +2666,7 @@ bnx2_alloc_bad_rbuf(struct bnx2 *bp)
        u32 good_mbuf_cnt;
        u32 val;
 
-       good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
+       good_mbuf = kmalloc_array(512, sizeof(u16), GFP_KERNEL);
        if (!good_mbuf)
                return -ENOMEM;
 
index 38f635cf840844b6a92a20587a9fcf7f9382b016..05d4059059062463ee8fa38d16a9a708f96cb411 100644 (file)
@@ -444,8 +444,8 @@ static int bnxt_vf_reps_create(struct bnxt *bp)
                return -ENOMEM;
 
        /* storage for cfa_code to vf-idx mapping */
-       cfa_code_map = kmalloc(sizeof(*bp->cfa_code_map) * MAX_CFA_CODE,
-                              GFP_KERNEL);
+       cfa_code_map = kmalloc_array(MAX_CFA_CODE, sizeof(*bp->cfa_code_map),
+                                    GFP_KERNEL);
        if (!cfa_code_map) {
                rc = -ENOMEM;
                goto err;
index 251d5bdc972f3daf0b6e3f241797ea966eb1ab5f..c301aaf79d647d2c0f2a1b08ebc1823d6079377f 100644 (file)
@@ -873,7 +873,7 @@ static int cctrl_tbl_show(struct seq_file *seq, void *v)
        u16 (*incr)[NCCTRL_WIN];
        struct adapter *adap = seq->private;
 
-       incr = kmalloc(sizeof(*incr) * NMTUS, GFP_KERNEL);
+       incr = kmalloc_array(NMTUS, sizeof(*incr), GFP_KERNEL);
        if (!incr)
                return -ENOMEM;
 
index 35cb3ae4f7b672069423275707943733e6a5d5fa..3001d8ed1a0cebf8d9c6894501be00fcc9720e44 100644 (file)
@@ -713,7 +713,7 @@ int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
        const struct sge_eth_rxq *rxq;
 
        rxq = &adapter->sge.ethrxq[pi->first_qset];
-       rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
+       rss = kmalloc_array(pi->rss_size, sizeof(u16), GFP_KERNEL);
        if (!rss)
                return -ENOMEM;
 
@@ -4972,8 +4972,8 @@ static int enable_msix(struct adapter *adap)
                max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
        if (is_offload(adap))
                max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
-       entries = kmalloc(sizeof(*entries) * (max_ingq + 1),
-                         GFP_KERNEL);
+       entries = kmalloc_array(max_ingq + 1, sizeof(*entries),
+                               GFP_KERNEL);
        if (!entries)
                return -ENOMEM;
 
index a96b838cffcebc62e21043f65dbfb9265cf16d79..42fca3208c0bac2e7a72f3f82d3350b85b6d9398 100644 (file)
@@ -2253,9 +2253,9 @@ static int ucc_geth_alloc_tx(struct ucc_geth_private *ugeth)
        /* Init Tx bds */
        for (j = 0; j < ug_info->numQueuesTx; j++) {
                /* Setup the skbuff rings */
-               ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
-                                             ugeth->ug_info->bdRingLenTx[j],
-                                             GFP_KERNEL);
+               ugeth->tx_skbuff[j] =
+                       kmalloc_array(ugeth->ug_info->bdRingLenTx[j],
+                                     sizeof(struct sk_buff *), GFP_KERNEL);
 
                if (ugeth->tx_skbuff[j] == NULL) {
                        if (netif_msg_ifup(ugeth))
@@ -2326,9 +2326,9 @@ static int ucc_geth_alloc_rx(struct ucc_geth_private *ugeth)
        /* Init Rx bds */
        for (j = 0; j < ug_info->numQueuesRx; j++) {
                /* Setup the skbuff rings */
-               ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
-                                             ugeth->ug_info->bdRingLenRx[j],
-                                             GFP_KERNEL);
+               ugeth->rx_skbuff[j] =
+                       kmalloc_array(ugeth->ug_info->bdRingLenRx[j],
+                                     sizeof(struct sk_buff *), GFP_KERNEL);
 
                if (ugeth->rx_skbuff[j] == NULL) {
                        if (netif_msg_ifup(ugeth))
index c1b51edaaf62560447c4753145091d9d2a238e84..525d8b89187b9b92eec16f2c33bc33c7524a3e4e 100644 (file)
@@ -171,7 +171,7 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
 {
        int i;
 
-       pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
+       pool->free_map = kmalloc_array(pool->size, sizeof(u16), GFP_KERNEL);
 
        if (!pool->free_map)
                return -1;
index 5d365a986bb08a05893bb46430f09bc7004e8f23..bdb3f8e65ed470e314bf6b4f9b3b3b4e41b93e0f 100644 (file)
@@ -435,8 +435,8 @@ static int e1000_get_eeprom(struct net_device *netdev,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) *
-                       (last_word - first_word + 1), GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index e084cb734eb1e7534da82c8ae729b4ae360bac20..02ebf208f48b27fcacc432c58945b3a936e6d266 100644 (file)
@@ -509,8 +509,8 @@ static int e1000_get_eeprom(struct net_device *netdev,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
-                             GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index 2d798499d35e5278d8fa80aa751de56a3bb983c2..0edd3cdd84b03924b3f9e80bda0b2605c0867ef9 100644 (file)
@@ -736,8 +736,8 @@ static int igb_get_eeprom(struct net_device *netdev,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) *
-                       (last_word - first_word + 1), GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
@@ -3245,8 +3245,8 @@ static int igb_get_module_eeprom(struct net_device *netdev,
        first_word = ee->offset >> 1;
        last_word = (ee->offset + ee->len - 1) >> 1;
 
-       dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
-                          GFP_KERNEL);
+       dataword = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                GFP_KERNEL);
        if (!dataword)
                return -ENOMEM;
 
index 43744bf0fc1cf0f4de4e9bcbcdd85008531259e4..c8c93ac436d4c8c1729c833411a415805d3cde73 100644 (file)
@@ -375,8 +375,9 @@ ixgb_get_eeprom(struct net_device *netdev,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(__le16) *
-                       (last_word - first_word + 1), GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1,
+                                   sizeof(__le16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index 62f2173bc20ed43b5268f7705c03c38f57aac0f8..43664adf7a3c120d024889ac59f42e2da5d5b1ae 100644 (file)
@@ -1093,8 +1093,9 @@ ixgb_set_multi(struct net_device *netdev)
                rctl |= IXGB_RCTL_MPE;
                IXGB_WRITE_REG(hw, RCTL, rctl);
        } else {
-               u8 *mta = kmalloc(IXGB_MAX_NUM_MULTICAST_ADDRESSES *
-                             ETH_ALEN, GFP_ATOMIC);
+               u8 *mta = kmalloc_array(ETH_ALEN,
+                                       IXGB_MAX_NUM_MULTICAST_ADDRESSES,
+                                       GFP_ATOMIC);
                u8 *addr;
                if (!mta)
                        goto alloc_failed;
index bdd179c29ea4ce5cb49fd4ea0b7d96436f5c82cc..be2636ea945b691225849fbcdf7810311bbd6c31 100644 (file)
@@ -901,7 +901,7 @@ static int ixgbe_get_eeprom(struct net_device *netdev,
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
        eeprom_len = last_word - first_word + 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
+       eeprom_buff = kmalloc_array(eeprom_len, sizeof(u16), GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index 6a9086dc1e92771fc454a1f0452b5f622c5f348c..03375c705df77b3d0c87f360f0cbd57831b9e7f3 100644 (file)
@@ -2636,9 +2636,9 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
        int i;
        int err = 0;
 
-       priv->cmd.context = kmalloc(priv->cmd.max_cmds *
-                                  sizeof(struct mlx4_cmd_context),
-                                  GFP_KERNEL);
+       priv->cmd.context = kmalloc_array(priv->cmd.max_cmds,
+                                         sizeof(struct mlx4_cmd_context),
+                                         GFP_KERNEL);
        if (!priv->cmd.context)
                return -ENOMEM;
 
index 6f57c052053e24e3ee2bde0e70ddd94c2edb7883..1f3372c1802ed0185cdb4f8ef309479549ceb3db 100644 (file)
@@ -1211,8 +1211,9 @@ int mlx4_init_eq_table(struct mlx4_dev *dev)
        }
 
        priv->eq_table.irq_names =
-               kmalloc(MLX4_IRQNAME_SIZE * (dev->caps.num_comp_vectors + 1),
-                       GFP_KERNEL);
+               kmalloc_array(MLX4_IRQNAME_SIZE,
+                             (dev->caps.num_comp_vectors + 1),
+                             GFP_KERNEL);
        if (!priv->eq_table.irq_names) {
                err = -ENOMEM;
                goto err_out_clr_int;
index 29e50f787349c986cdb8b954c783b54efeab770f..b0e11255a355fdda9059796e0df7a838cbf107d8 100644 (file)
@@ -507,10 +507,12 @@ int mlx4_init_resource_tracker(struct mlx4_dev *dev)
        for (i = 0; i < MLX4_NUM_OF_RESOURCE_TYPE; i++) {
                struct resource_allocator *res_alloc =
                        &priv->mfunc.master.res_tracker.res_alloc[i];
-               res_alloc->quota = kmalloc((dev->persist->num_vfs + 1) *
-                                          sizeof(int), GFP_KERNEL);
-               res_alloc->guaranteed = kmalloc((dev->persist->num_vfs + 1) *
-                                               sizeof(int), GFP_KERNEL);
+               res_alloc->quota = kmalloc_array(dev->persist->num_vfs + 1,
+                                                sizeof(int),
+                                                GFP_KERNEL);
+               res_alloc->guaranteed = kmalloc_array(dev->persist->num_vfs + 1,
+                                                     sizeof(int),
+                                                     GFP_KERNEL);
                if (i == RES_MAC || i == RES_VLAN)
                        res_alloc->allocated = kzalloc(MLX4_MAX_PORTS *
                                                       (dev->persist->num_vfs
index 2e4effa9fe456d4c0e8029136bf99cffad407dd2..b34055ac476f72191ca498ad11808f47fedac767 100644 (file)
@@ -507,15 +507,15 @@ static int moxart_mac_probe(struct platform_device *pdev)
                goto init_fail;
        }
 
-       priv->tx_buf_base = kmalloc(priv->tx_buf_size * TX_DESC_NUM,
-                                   GFP_ATOMIC);
+       priv->tx_buf_base = kmalloc_array(priv->tx_buf_size, TX_DESC_NUM,
+                                         GFP_ATOMIC);
        if (!priv->tx_buf_base) {
                ret = -ENOMEM;
                goto init_fail;
        }
 
-       priv->rx_buf_base = kmalloc(priv->rx_buf_size * RX_DESC_NUM,
-                                   GFP_ATOMIC);
+       priv->rx_buf_base = kmalloc_array(priv->rx_buf_size, RX_DESC_NUM,
+                                         GFP_ATOMIC);
        if (!priv->rx_buf_base) {
                ret = -ENOMEM;
                goto init_fail;
index 66c665d0b92647cfc531eebb4dd2b4486a851b13..7cbd0174459ceabb43fd1cabe96aece2dce92d27 100644 (file)
@@ -4630,8 +4630,10 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
                                               ring->tx_pending),
                                               &ring_addr, GFP_ATOMIC);
        }
-       rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
-       tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
+       rx_skbuff = kmalloc_array(ring->rx_pending, sizeof(struct nv_skb_map),
+                                 GFP_KERNEL);
+       tx_skbuff = kmalloc_array(ring->tx_pending, sizeof(struct nv_skb_map),
+                                 GFP_KERNEL);
        if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
                /* fall back to old rings */
                if (!nv_optimized(np)) {
index 7cd494611a74027a9b2867dabc9073c1d1235662..34a1581eda95578b6350eeedf3c7372e4388953a 100644 (file)
@@ -2178,7 +2178,7 @@ static void pch_gbe_set_multi(struct net_device *netdev)
 
        if (mc_count >= PCH_GBE_MAR_ENTRIES)
                return;
-       mta_list = kmalloc(mc_count * ETH_ALEN, GFP_ATOMIC);
+       mta_list = kmalloc_array(ETH_ALEN, mc_count, GFP_ATOMIC);
        if (!mta_list)
                return;
 
index 6f9927d1a50197f2484aab1e03450febef52bd6a..4e0b443c9519d67bc3b888ddf3b341c93291e328 100644 (file)
@@ -2578,9 +2578,9 @@ int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn)
                goto err0;
        }
 
-       nvm_info->image_att = kmalloc(nvm_info->num_images *
-                                     sizeof(struct bist_nvm_image_att),
-                                     GFP_KERNEL);
+       nvm_info->image_att = kmalloc_array(nvm_info->num_images,
+                                           sizeof(struct bist_nvm_image_att),
+                                           GFP_KERNEL);
        if (!nvm_info->image_att) {
                rc = -ENOMEM;
                goto err0;
index 70de062b72a15f45972079149f5c414d4d035283..353f1c129af1e247e1a8ddaa6d316edfc285682d 100644 (file)
@@ -2810,7 +2810,8 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev,
                goto pci_alloc_err;
 
        tx_ring->q =
-           kmalloc(tx_ring->wq_len * sizeof(struct tx_ring_desc), GFP_KERNEL);
+           kmalloc_array(tx_ring->wq_len, sizeof(struct tx_ring_desc),
+                         GFP_KERNEL);
        if (tx_ring->q == NULL)
                goto err;
 
index f38e32a7ec9c979ac4524c31e09da375a6e0606c..ec629a730005273924c40ace6977ad7fedecc315 100644 (file)
@@ -742,11 +742,13 @@ static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize)
 {
        int i;
 
-       gtp->addr_hash = kmalloc(sizeof(struct hlist_head) * hsize, GFP_KERNEL);
+       gtp->addr_hash = kmalloc_array(hsize, sizeof(struct hlist_head),
+                                      GFP_KERNEL);
        if (gtp->addr_hash == NULL)
                return -ENOMEM;
 
-       gtp->tid_hash = kmalloc(sizeof(struct hlist_head) * hsize, GFP_KERNEL);
+       gtp->tid_hash = kmalloc_array(hsize, sizeof(struct hlist_head),
+                                     GFP_KERNEL);
        if (gtp->tid_hash == NULL)
                goto err1;
 
index f411164880799a4ac57a3de8469cd6f4d848dce7..029206e4da3b3719084ccdc4cbc7486313237cff 100644 (file)
@@ -1583,7 +1583,7 @@ static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        return -EPERM;
                }
 
-               image = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
+               image = kmalloc_array(EEPROM_WORDS, sizeof(u32), GFP_KERNEL);
                if (!image)
                        return -ENOMEM;
 
index 8863fa02350084ea5deea072900cdcf6d8e69b54..ca0af0e15a2cc9f7d2b957340cf00d615c7f2440 100644 (file)
@@ -791,7 +791,8 @@ static int team_queue_override_init(struct team *team)
 
        if (!queue_cnt)
                return 0;
-       listarr = kmalloc(sizeof(struct list_head) * queue_cnt, GFP_KERNEL);
+       listarr = kmalloc_array(queue_cnt, sizeof(struct list_head),
+                               GFP_KERNEL);
        if (!listarr)
                return -ENOMEM;
        team->qom_lists = listarr;
index f4d7362eb325618254aebf2130757da0fb888472..e95dd12edec473198125c18c1cec6bc7d32ec368 100644 (file)
@@ -640,8 +640,8 @@ int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
-                             GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
@@ -680,8 +680,8 @@ int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
-                             GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index a6ef75907ae91ef0cf13d8b04cadaed99b31b969..9e8ad372f4190eed1d4e92891193d325c44fb47f 100644 (file)
@@ -599,8 +599,8 @@ ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
 
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
-       eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
-                             GFP_KERNEL);
+       eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
+                                   GFP_KERNEL);
        if (!eeprom_buff)
                return -ENOMEM;
 
index d9eea8cfe6cb9a3bf8d0d4ce9198af9bccf9c757..770aa624147f170abd330d7820bc995ef9a712e6 100644 (file)
@@ -1323,8 +1323,8 @@ static int build_dma_sg(const struct sk_buff *skb, struct urb *urb)
                return 0;
 
        /* reserve one for zero packet */
-       urb->sg = kmalloc((num_sgs + 1) * sizeof(struct scatterlist),
-                         GFP_ATOMIC);
+       urb->sg = kmalloc_array(num_sgs + 1, sizeof(struct scatterlist),
+                               GFP_ATOMIC);
        if (!urb->sg)
                return -ENOMEM;
 
index 1619ee3070b6213cb9b9cc65e8fb146a2894ebdf..15b9a83bbd9d29e84a076ac7d1030e71768b37d5 100644 (file)
@@ -2555,10 +2555,10 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
        vqs = kzalloc(total_vqs * sizeof(*vqs), GFP_KERNEL);
        if (!vqs)
                goto err_vq;
-       callbacks = kmalloc(total_vqs * sizeof(*callbacks), GFP_KERNEL);
+       callbacks = kmalloc_array(total_vqs, sizeof(*callbacks), GFP_KERNEL);
        if (!callbacks)
                goto err_callback;
-       names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
+       names = kmalloc_array(total_vqs, sizeof(*names), GFP_KERNEL);
        if (!names)
                goto err_names;
        if (!vi->big_packets || vi->mergeable_rx_bufs) {
index 641b13a279e18a0a681f87ee1965184cc97a1070..b1b8bc3268309ecff781d981a7563a5c024aa0ac 100644 (file)
@@ -890,7 +890,8 @@ ath5k_hw_rfregs_init(struct ath5k_hw *ah,
         * ah->ah_rf_banks based on ah->ah_rf_banks_size
         * we set above */
        if (ah->ah_rf_banks == NULL) {
-               ah->ah_rf_banks = kmalloc(sizeof(u32) * ah->ah_rf_banks_size,
+               ah->ah_rf_banks = kmalloc_array(ah->ah_rf_banks_size,
+                                                               sizeof(u32),
                                                                GFP_KERNEL);
                if (ah->ah_rf_banks == NULL) {
                        ATH5K_ERR(ah, "out of memory\n");
index 6343cc91953e8090e753a7e26e74cf5339ee6b1c..34e1009402846c854b22d9d32c4f70e21465b518 100644 (file)
@@ -925,7 +925,7 @@ int ar9003_paprd_create_curve(struct ath_hw *ah,
 
        memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain]));
 
-       buf = kmalloc(2 * 48 * sizeof(u32), GFP_KERNEL);
+       buf = kmalloc_array(2 * 48, sizeof(u32), GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
index 6b37036b2d361fcef5e5b3f724a76cd79a4ac759..e60bea4604e4104dbcc837ddf23ecd890a299e2e 100644 (file)
@@ -127,13 +127,13 @@ void ath9k_hw_read_array(struct ath_hw *ah, u32 array[][2], int size)
        u32 *tmp_reg_list, *tmp_data;
        int i;
 
-       tmp_reg_list = kmalloc(size * sizeof(u32), GFP_KERNEL);
+       tmp_reg_list = kmalloc_array(size, sizeof(u32), GFP_KERNEL);
        if (!tmp_reg_list) {
                dev_err(ah->dev, "%s: tmp_reg_list: alloc filed\n", __func__);
                return;
        }
 
-       tmp_data = kmalloc(size * sizeof(u32), GFP_KERNEL);
+       tmp_data = kmalloc_array(size, sizeof(u32), GFP_KERNEL);
        if (!tmp_data) {
                dev_err(ah->dev, "%s tmp_data: alloc filed\n", __func__);
                goto error_tmp_data;
index 9d830d27b22926a73fea9ab681c50a8dfb5951d4..9fb0d9fbd93958e11b4eca19428c280a198f5628 100644 (file)
@@ -1387,7 +1387,7 @@ wlc_lcnphy_rx_iq_cal(struct brcms_phy *pi,
        s16 *ptr;
        struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
 
-       ptr = kmalloc(sizeof(s16) * 131, GFP_ATOMIC);
+       ptr = kmalloc_array(131, sizeof(s16), GFP_ATOMIC);
        if (NULL == ptr)
                return false;
        if (module == 2) {
@@ -2670,7 +2670,7 @@ wlc_lcnphy_tx_iqlo_cal(struct brcms_phy *pi,
        u16 *values_to_save;
        struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
 
-       values_to_save = kmalloc(sizeof(u16) * 20, GFP_ATOMIC);
+       values_to_save = kmalloc_array(20, sizeof(u16), GFP_ATOMIC);
        if (NULL == values_to_save)
                return;
 
@@ -3678,11 +3678,11 @@ wlc_lcnphy_a1(struct brcms_phy *pi, int cal_type, int num_levels,
        u16 *phy_c32;
        phy_c21 = 0;
        phy_c10 = phy_c13 = phy_c14 = phy_c8 = 0;
-       ptr = kmalloc(sizeof(s16) * 131, GFP_ATOMIC);
+       ptr = kmalloc_array(131, sizeof(s16), GFP_ATOMIC);
        if (NULL == ptr)
                return;
 
-       phy_c32 = kmalloc(sizeof(u16) * 20, GFP_ATOMIC);
+       phy_c32 = kmalloc_array(20, sizeof(u16), GFP_ATOMIC);
        if (NULL == phy_c32) {
                kfree(ptr);
                return;
index 7e01981bc5c8bf70475712c0942aa8cfe36c7c94..1a187557982e6c2d63f9c37e37229cf375ffd135 100644 (file)
@@ -23032,7 +23032,7 @@ wlc_phy_loadsampletable_nphy(struct brcms_phy *pi, struct cordic_iq *tone_buf,
        u16 t;
        u32 *data_buf = NULL;
 
-       data_buf = kmalloc(sizeof(u32) * num_samps, GFP_ATOMIC);
+       data_buf = kmalloc_array(num_samps, sizeof(u32), GFP_ATOMIC);
        if (data_buf == NULL)
                return;
 
@@ -23074,7 +23074,8 @@ wlc_phy_gen_load_samples_nphy(struct brcms_phy *pi, u32 f_kHz, u16 max_val,
                tbl_len = (phy_bw << 1);
        }
 
-       tone_buf = kmalloc(sizeof(struct cordic_iq) * tbl_len, GFP_ATOMIC);
+       tone_buf = kmalloc_array(tbl_len, sizeof(struct cordic_iq),
+                                GFP_ATOMIC);
        if (tone_buf == NULL)
                return 0;
 
index ce0fbf83285f4b8448c9cdd9a8a289373ad52aa0..72046e182745dc72d00462285c4d8e55d42a74e5 100644 (file)
@@ -7127,7 +7127,7 @@ static int airo_get_aplist(struct net_device *dev,
        int i;
        int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
 
-       qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
+       qual = kmalloc_array(IW_MAX_AP, sizeof(*qual), GFP_KERNEL);
        if (!qual)
                return -ENOMEM;
 
index 7c4f550a1475d24dd87a6c075b8ff423a250243b..b8fd3cc90634d116af789caeae309444fffae42b 100644 (file)
@@ -3445,8 +3445,9 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
        dma_addr_t p;
 
        priv->msg_buffers =
-           kmalloc(IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
-                   GFP_KERNEL);
+           kmalloc_array(IPW_COMMAND_POOL_SIZE,
+                         sizeof(struct ipw2100_tx_packet),
+                         GFP_KERNEL);
        if (!priv->msg_buffers)
                return -ENOMEM;
 
@@ -4587,9 +4588,9 @@ static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
        /*
         * allocate packets
         */
-       priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH *
-                                  sizeof(struct ipw2100_rx_packet),
-                                  GFP_KERNEL);
+       priv->rx_buffers = kmalloc_array(RX_QUEUE_LENGTH,
+                                        sizeof(struct ipw2100_rx_packet),
+                                        GFP_KERNEL);
        if (!priv->rx_buffers) {
                IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
 
index f26beeb6c5ffe671a5b32394a14e15d454eed049..8a858f7e36f445374843b3090638f23ef28357be 100644 (file)
@@ -3208,13 +3208,13 @@ static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
 
        IPW_DEBUG_TRACE("<< :\n");
 
-       virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
-                       GFP_KERNEL);
+       virts = kmalloc_array(CB_NUMBER_OF_ELEMENTS_SMALL, sizeof(void *),
+                             GFP_KERNEL);
        if (!virts)
                return -ENOMEM;
 
-       phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
-                       GFP_KERNEL);
+       phys = kmalloc_array(CB_NUMBER_OF_ELEMENTS_SMALL, sizeof(dma_addr_t),
+                            GFP_KERNEL);
        if (!phys) {
                kfree(virts);
                return -ENOMEM;
@@ -3782,7 +3782,7 @@ static int ipw_queue_tx_init(struct ipw_priv *priv,
 {
        struct pci_dev *dev = priv->pci_dev;
 
-       q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
+       q->txb = kmalloc_array(count, sizeof(q->txb[0]), GFP_KERNEL);
        if (!q->txb) {
                IPW_ERROR("vmalloc for auxiliary BD structures failed\n");
                return -ENOMEM;
index de8a099a938636f77f0b47105e4903fe89ec0c5e..da8c30f10d92398c6ca2064e449f8e98f9cc2f94 100644 (file)
@@ -271,8 +271,9 @@ static void prism2_info_scanresults(local_info_t *local, unsigned char *buf,
        left -= 4;
 
        new_count = left / sizeof(struct hfa384x_scan_result);
-       results = kmalloc(new_count * sizeof(struct hfa384x_hostscan_result),
-                         GFP_ATOMIC);
+       results = kmalloc_array(new_count,
+                               sizeof(struct hfa384x_hostscan_result),
+                               GFP_ATOMIC);
        if (results == NULL)
                return;
 
index c1bc0a6ef300fd4ab73e5971fe66e582e47a0a89..1ca9731d9b14b181117fc6a6ad28b40e97cb35e6 100644 (file)
@@ -513,8 +513,8 @@ static int prism2_ioctl_giwaplist(struct net_device *dev,
                return -EOPNOTSUPP;
        }
 
-       addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
-       qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
+       addr = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
+       qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
        if (addr == NULL || qual == NULL) {
                kfree(addr);
                kfree(qual);
index b01b44a5d16ead6b9dddc71c198f28d385027621..1f6d9f357e57de8d733e86de73ac90b64cf3ffd5 100644 (file)
@@ -732,7 +732,8 @@ static int zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon,
 
        /* Alloc memory for full beacon write at once. */
        num_cmds = 1 + zd_chip_is_zd1211b(&mac->chip) + full_len;
-       ioreqs = kmalloc(num_cmds * sizeof(struct zd_ioreq32), GFP_KERNEL);
+       ioreqs = kmalloc_array(num_cmds, sizeof(struct zd_ioreq32),
+                              GFP_KERNEL);
        if (!ioreqs) {
                r = -ENOMEM;
                goto out_nofree;
index 102646fedb5602b94c7f223aa4b2ffe32d5f25e0..ac0672b8dfca4d8245c49e74ded32923054f022a 100644 (file)
@@ -1481,11 +1481,11 @@ static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf,
        u_char *tuplebuffer;
        u_char *tempbuffer;
 
-       tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
+       tuplebuffer = kmalloc_array(256, sizeof(u_char), GFP_KERNEL);
        if (!tuplebuffer)
                return -ENOMEM;
 
-       tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
+       tempbuffer = kmalloc_array(258, sizeof(u_char), GFP_KERNEL);
        if (!tempbuffer) {
                ret = -ENOMEM;
                goto free_tuple;
index e582a21cfe549640f8e2b07b67401644b89f3bea..844537681fd72d77b665bc481beb9990e741481c 100644 (file)
@@ -81,7 +81,8 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,
                        map_num++;
        }
 
-       new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
+       new_map = kmalloc_array(map_num, sizeof(struct pinctrl_map),
+                               GFP_KERNEL);
        if (!new_map)
                return -ENOMEM;
 
index 5af89de0ff02c91c44bedf866ba8728749653d1c..e7169ac7799f48ebfe3c39927041bb783d7e0b6b 100644 (file)
@@ -241,7 +241,8 @@ static int imx1_dt_node_to_map(struct pinctrl_dev *pctldev,
        for (i = 0; i < grp->npins; i++)
                map_num++;
 
-       new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
+       new_map = kmalloc_array(map_num, sizeof(struct pinctrl_map),
+                               GFP_KERNEL);
        if (!new_map)
                return -ENOMEM;
 
index 25e80a5370ca02f65999abd8932aec8b6aa05fc6..44459d28efd5042454012b0e69f4ed060c2ba79e 100644 (file)
@@ -352,7 +352,7 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
         * any configuration.
         */
        nmaps = npins * 2;
-       *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL);
+       *map = kmalloc_array(nmaps, sizeof(struct pinctrl_map), GFP_KERNEL);
        if (!*map)
                return -ENOMEM;
 
index fb2c3599d95c20e3d2cc7f400889e65aea6449c6..0af8c5295b650b1132e5946b123b558a08e91ccc 100644 (file)
@@ -561,8 +561,8 @@ static int dasd_eer_open(struct inode *inp, struct file *filp)
                return -EINVAL;
        }
        eerb->buffersize = eerb->buffer_page_count * PAGE_SIZE;
-       eerb->buffer = kmalloc(eerb->buffer_page_count * sizeof(char *),
-                              GFP_KERNEL);
+       eerb->buffer = kmalloc_array(eerb->buffer_page_count, sizeof(char *),
+                                    GFP_KERNEL);
         if (!eerb->buffer) {
                kfree(eerb);
                 return -ENOMEM;
index 1c98023cffd4165a8ad5117c907fa9258d918c4f..5b8af278228282914a4250ee655aa4f85355ef7f 100644 (file)
@@ -719,7 +719,8 @@ tty3270_alloc_view(void)
        if (!tp)
                goto out_err;
        tp->freemem_pages =
-               kmalloc(sizeof(void *) * TTY3270_STRING_PAGES, GFP_KERNEL);
+               kmalloc_array(TTY3270_STRING_PAGES, sizeof(void *),
+                             GFP_KERNEL);
        if (!tp->freemem_pages)
                goto out_tp;
        INIT_LIST_HEAD(&tp->freemem);
index ed80d00cdb6f132e2e7a01394dcf046eed9c0c89..a9ae827cc1ce84f8042c8bceda48d4d89283baed 100644 (file)
@@ -899,9 +899,9 @@ int pkey_findcard(const struct pkey_seckey *seckey,
                return -EINVAL;
 
        /* fetch status of all crypto cards */
-       device_status = kmalloc(MAX_ZDEV_ENTRIES_EXT
-                               * sizeof(struct zcrypt_device_status_ext),
-                               GFP_KERNEL);
+       device_status = kmalloc_array(MAX_ZDEV_ENTRIES_EXT,
+                                     sizeof(struct zcrypt_device_status_ext),
+                                     GFP_KERNEL);
        if (!device_status)
                return -ENOMEM;
        zcrypt_device_status_mask_ext(device_status);
index e7961cbd2c55ab81020084730e8ec19f45aeda7d..a9831bd37a73d52462489d025c1631a576ca2fbc 100644 (file)
@@ -4132,7 +4132,7 @@ static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int
        if (aac_convert_sgl == 0)
                return 0;
 
-       sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
+       sge = kmalloc_array(nseg_new, sizeof(struct sge_ieee1212), GFP_ATOMIC);
        if (sge == NULL)
                return -ENOMEM;
 
index 124217927c4af267554733df8cad79afe9cc7bee..41add33e3f1f5babe73333cb8663546c4f75f61f 100644 (file)
@@ -400,7 +400,8 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
 #endif
        if (bufflen) {  /* allocate memory before taking host_lock */
                sg_count = scsi_sg_count(cmd);
-               cptr = kmalloc(sizeof(*cptr) * sg_count, GFP_KERNEL | GFP_DMA);
+               cptr = kmalloc_array(sg_count, sizeof(*cptr),
+                                    GFP_KERNEL | GFP_DMA);
                if (!cptr)
                        return SCSI_MLQUEUE_HOST_BUSY;
        } else {
index 034f4eebb1603f6271c929e51a304660fae6ac30..67d292dcc60766832a6c4edbb8f3971c94791215 100644 (file)
@@ -7063,7 +7063,8 @@ ahd_init(struct ahd_softc *ahd)
        AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
 
        ahd->stack_size = ahd_probe_stack_size(ahd);
-       ahd->saved_stack = kmalloc(ahd->stack_size * sizeof(uint16_t), GFP_ATOMIC);
+       ahd->saved_stack = kmalloc_array(ahd->stack_size, sizeof(uint16_t),
+                                        GFP_ATOMIC);
        if (ahd->saved_stack == NULL)
                return (ENOMEM);
 
index 2dbc8330d7d34b4e9904e88f6ae79778c50cd07c..35e0b5b64e8fa6f2f98a39db10d6598b8bfc2db9 100644 (file)
@@ -291,7 +291,8 @@ static int asd_alloc_edbs(struct asd_ha_struct *asd_ha, gfp_t gfp_flags)
        struct asd_seq_data *seq = &asd_ha->seq;
        int i;
 
-       seq->edb_arr = kmalloc(seq->num_edbs*sizeof(*seq->edb_arr), gfp_flags);
+       seq->edb_arr = kmalloc_array(seq->num_edbs, sizeof(*seq->edb_arr),
+                                    gfp_flags);
        if (!seq->edb_arr)
                return -ENOMEM;
 
@@ -323,8 +324,8 @@ static int asd_alloc_escbs(struct asd_ha_struct *asd_ha,
        struct asd_ascb *escb;
        int i, escbs;
 
-       seq->escb_arr = kmalloc(seq->num_escbs*sizeof(*seq->escb_arr),
-                               gfp_flags);
+       seq->escb_arr = kmalloc_array(seq->num_escbs, sizeof(*seq->escb_arr),
+                                     gfp_flags);
        if (!seq->escb_arr)
                return -ENOMEM;
 
index 3441ce3ebabfed136f79560d734e37874837177c..996dfe9039285dd9fb1a0914f5dc3d98f7aa0d5b 100644 (file)
@@ -70,7 +70,7 @@ int queue_initialise (Queue_t *queue)
         * need to keep free lists or allocate this
         * memory.
         */
-       queue->alloc = q = kmalloc(sizeof(QE_t) * nqueues, GFP_KERNEL);
+       queue->alloc = q = kmalloc_array(nqueues, sizeof(QE_t), GFP_KERNEL);
        if (q) {
                for (; nqueues; q++, nqueues--) {
                        SET_MAGIC(q, QUEUE_MAGIC_FREE);
index b3cfdd5f4d1c3812baf40f34c936b53f3b34acdf..d981c16cd61116522b811d448cd9de96c60dbbac 100644 (file)
@@ -2483,8 +2483,9 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
                return -ENOMEM;
        }
 
-       mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
-                              GFP_KERNEL);
+       mem_arr_orig = kmalloc_array(BEISCSI_MAX_FRAGS_INIT,
+                                    sizeof(*mem_arr_orig),
+                                    GFP_KERNEL);
        if (!mem_arr_orig) {
                kfree(phba->init_mem);
                kfree(phwi_ctrlr->wrb_context);
@@ -2533,8 +2534,8 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
                } while (alloc_size);
                mem_descr->num_elements = j;
                mem_descr->size_in_bytes = phba->mem_req[i];
-               mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
-                                              GFP_KERNEL);
+               mem_descr->mem_array = kmalloc_array(j, sizeof(*mem_arr),
+                                                    GFP_KERNEL);
                if (!mem_descr->mem_array)
                        goto free_mem;
 
@@ -3353,8 +3354,9 @@ beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
        idx = 0;
        mem_descr = phba->init_mem;
        mem_descr += HWI_MEM_WRB;
-       pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
-                          GFP_KERNEL);
+       pwrb_arr = kmalloc_array(phba->params.cxns_per_ctrl,
+                                sizeof(*pwrb_arr),
+                                GFP_KERNEL);
        if (!pwrb_arr) {
                beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
                            "BM_%d : Memory alloc failed in create wrb ring.\n");
index 097f37de6ce91231082353f327485d8f189d68ba..ea23c8dffc252af3d0209167e99118c98575d848 100644 (file)
@@ -1390,8 +1390,8 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
         */
        num_vlink_desc = rlen / sizeof(*vp);
        if (num_vlink_desc)
-               vlink_desc_arr = kmalloc(sizeof(vp) * num_vlink_desc,
-                                        GFP_ATOMIC);
+               vlink_desc_arr = kmalloc_array(num_vlink_desc, sizeof(vp),
+                                              GFP_ATOMIC);
        if (!vlink_desc_arr)
                return;
        num_vlink_desc = 0;
index 3a9eca163db8117e7bbf1132c7965d5253850668..e6f31fa9ec65f0019d2f4cf8b1c70692ed85f217 100644 (file)
@@ -2177,8 +2177,9 @@ static int hpsa_allocate_ioaccel2_sg_chain_blocks(struct ctlr_info *h)
                return -ENOMEM;
        for (i = 0; i < h->nr_cmds; i++) {
                h->ioaccel2_cmd_sg_list[i] =
-                       kmalloc(sizeof(*h->ioaccel2_cmd_sg_list[i]) *
-                                       h->maxsgentries, GFP_KERNEL);
+                       kmalloc_array(h->maxsgentries,
+                                     sizeof(*h->ioaccel2_cmd_sg_list[i]),
+                                     GFP_KERNEL);
                if (!h->ioaccel2_cmd_sg_list[i])
                        goto clean;
        }
@@ -2216,8 +2217,9 @@ static int hpsa_alloc_sg_chain_blocks(struct ctlr_info *h)
                return -ENOMEM;
 
        for (i = 0; i < h->nr_cmds; i++) {
-               h->cmd_sg_list[i] = kmalloc(sizeof(*h->cmd_sg_list[i]) *
-                                               h->chainsize, GFP_KERNEL);
+               h->cmd_sg_list[i] = kmalloc_array(h->chainsize,
+                                                 sizeof(*h->cmd_sg_list[i]),
+                                                 GFP_KERNEL);
                if (!h->cmd_sg_list[i])
                        goto clean;
 
@@ -6407,7 +6409,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
                status = -ENOMEM;
                goto cleanup1;
        }
-       buff_size = kmalloc(SG_ENTRIES_IN_CMD * sizeof(int), GFP_KERNEL);
+       buff_size = kmalloc_array(SG_ENTRIES_IN_CMD, sizeof(int), GFP_KERNEL);
        if (!buff_size) {
                status = -ENOMEM;
                goto cleanup1;
@@ -7151,7 +7153,7 @@ static int controller_reset_failed(struct CfgTable __iomem *cfgtable)
        char *driver_ver, *old_driver_ver;
        int rc, size = sizeof(cfgtable->driver_version);
 
-       old_driver_ver = kmalloc(2 * size, GFP_KERNEL);
+       old_driver_ver = kmalloc_array(2, size, GFP_KERNEL);
        if (!old_driver_ver)
                return -ENOMEM;
        driver_ver = old_driver_ver + size;
index 41361662ff08175dfde84358bb18c59d318d5d52..0758edb9dfe24cd1c5aea26fe8e1434a8031224f 100644 (file)
@@ -120,8 +120,9 @@ lpfc_mem_alloc(struct lpfc_hba *phba, int align)
        if (!phba->lpfc_mbuf_pool)
                goto fail_free_dma_buf_pool;
 
-       pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
-                                        LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
+       pool->elements = kmalloc_array(LPFC_MBUF_POOL_SIZE,
+                                      sizeof(struct lpfc_dmabuf),
+                                      GFP_KERNEL);
        if (!pool->elements)
                goto fail_free_lpfc_mbuf_pool;
 
index 8c4d3003b68b2ed087b73ec41f036105b367f754..177701dfdfcbcd7e7b3ff4c92ce7c639bcddd730 100644 (file)
@@ -464,8 +464,9 @@ static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *mat
                 * +1 to allow for aligning.
         * XXX FIXME: Use DMA consistent routines
         */
-               dma_cmd_space = kmalloc((host->sg_tablesize + 2) *
-                                       sizeof(struct dbdma_cmd), GFP_KERNEL);
+               dma_cmd_space = kmalloc_array(host->sg_tablesize + 2,
+                                            sizeof(struct dbdma_cmd),
+                                            GFP_KERNEL);
                if (dma_cmd_space == 0) {
                        printk(KERN_ERR "mac53c94: couldn't allocate dma "
                               "command space for %pOF\n", node);
index 3b3767e240d89db30eea8f4f019ac9bdc13bf880..8e8cf1145d7f0d8c03cdb70634559a9f5f710ace 100644 (file)
@@ -4292,7 +4292,8 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
                goto out_host_put;
        }
 
-       adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
+       adapter->scb_list = kmalloc_array(MAX_COMMANDS, sizeof(scb_t),
+                                         GFP_KERNEL);
        if (!adapter->scb_list) {
                dev_warn(&pdev->dev, "out of RAM\n");
                goto out_free_cmd_buffer;
index bb802b0c12b8663570dbc57bf6f032d575360e7a..8428247015db6f0c0b5890054e90bb741614feb6 100644 (file)
@@ -935,10 +935,12 @@ mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
         * Allocate single blocks of memory for all required kiocs,
         * mailboxes and passthru structures.
         */
-       adapter->kioc_list      = kmalloc(sizeof(uioc_t) * lld_adp->max_kioc,
-                                               GFP_KERNEL);
-       adapter->mbox_list      = kmalloc(sizeof(mbox64_t) * lld_adp->max_kioc,
-                                               GFP_KERNEL);
+       adapter->kioc_list      = kmalloc_array(lld_adp->max_kioc,
+                                                 sizeof(uioc_t),
+                                                 GFP_KERNEL);
+       adapter->mbox_list      = kmalloc_array(lld_adp->max_kioc,
+                                                 sizeof(mbox64_t),
+                                                 GFP_KERNEL);
        adapter->pthru_dma_pool = dma_pool_create("megaraid mm pthru pool",
                                                &adapter->pdev->dev,
                                                sizeof(mraid_passthru_t),
index 2bbe797f8c3dae62118c88b26537737a2215052a..773c4bfeb0f88d8bb1b48c74bfc40392f2dde14d 100644 (file)
@@ -5856,7 +5856,9 @@ static int osst_probe(struct device *dev)
        /* if this is the first attach, build the infrastructure */
        write_lock(&os_scsi_tapes_lock);
        if (os_scsi_tapes == NULL) {
-               os_scsi_tapes = kmalloc(osst_max_dev * sizeof(struct osst_tape *), GFP_ATOMIC);
+               os_scsi_tapes = kmalloc_array(osst_max_dev,
+                                              sizeof(struct osst_tape *),
+                                              GFP_ATOMIC);
                if (os_scsi_tapes == NULL) {
                        write_unlock(&os_scsi_tapes_lock);
                        printk(KERN_ERR "osst :E: Unable to allocate array for OnStream SCSI tapes.\n");
index 872d66dd79cd6e7966e381431e69b73cd88d8fac..de2bc78449e786500b0680411d6245895ac43790 100644 (file)
@@ -1230,7 +1230,7 @@ qla82xx_pinit_from_rom(scsi_qla_host_t *vha)
        ql_log(ql_log_info, vha, 0x0072,
            "%d CRB init values found in ROM.\n", n);
 
-       buf = kmalloc(n * sizeof(struct crb_addr_pair), GFP_KERNEL);
+       buf = kmalloc_array(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
        if (buf == NULL) {
                ql_log(ql_log_fatal, vha, 0x010c,
                    "Unable to allocate memory.\n");
index 43f73583ef5c4a9abbb3ec43d2ac8aa2cf0493b2..d2b333d629be25077bb7ae09d4fc4070726c21b6 100644 (file)
@@ -1077,7 +1077,7 @@ qla4_82xx_pinit_from_rom(struct scsi_qla_host *ha, int verbose)
        ql4_printk(KERN_INFO, ha,
                "%s: %d CRB init values found in ROM.\n", DRIVER_NAME, n);
 
-       buf = kmalloc(n * sizeof(struct crb_addr_pair), GFP_KERNEL);
+       buf = kmalloc_array(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
        if (buf == NULL) {
                ql4_printk(KERN_WARNING, ha,
                    "%s: [ERROR] Unable to malloc memory.\n", DRIVER_NAME);
index 592b6dbf8b3592396152aee2af597f32f4512b09..8332f958cc42d44bc5992683704010caa1342a11 100644 (file)
@@ -1820,8 +1820,9 @@ static int pqi_update_scsi_devices(struct pqi_ctrl_info *ctrl_info)
 
        num_new_devices = num_physicals + num_logicals;
 
-       new_device_list = kmalloc(sizeof(*new_device_list) *
-               num_new_devices, GFP_KERNEL);
+       new_device_list = kmalloc_array(num_new_devices,
+                                       sizeof(*new_device_list),
+                                       GFP_KERNEL);
        if (!new_device_list) {
                dev_warn(&ctrl_info->pci_dev->dev, "%s\n", out_of_memory_msg);
                rc = -ENOMEM;
index c9e27e752c2545dff1a3714ce5817f7e3036e07b..c16e4de3a03fdceed284e73c9020bb231efb341c 100644 (file)
@@ -4915,7 +4915,8 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
        if (count == 0)
                return 0;
 
-       if ((pages = kmalloc(max_pages * sizeof(*pages), GFP_KERNEL)) == NULL)
+       pages = kmalloc_array(max_pages, sizeof(*pages), GFP_KERNEL);
+       if (pages == NULL)
                return -ENOMEM;
 
         /* Try to fault in all of the necessary pages */
index 45d04631888a4f67d0884971226074c6628a063d..6dc8891ccb745a8b1bb259de3fd03e46715d9325 100644 (file)
@@ -794,9 +794,10 @@ static int virtscsi_init(struct virtio_device *vdev,
        struct irq_affinity desc = { .pre_vectors = 2 };
 
        num_vqs = vscsi->num_queues + VIRTIO_SCSI_VQ_BASE;
-       vqs = kmalloc(num_vqs * sizeof(struct virtqueue *), GFP_KERNEL);
-       callbacks = kmalloc(num_vqs * sizeof(vq_callback_t *), GFP_KERNEL);
-       names = kmalloc(num_vqs * sizeof(char *), GFP_KERNEL);
+       vqs = kmalloc_array(num_vqs, sizeof(struct virtqueue *), GFP_KERNEL);
+       callbacks = kmalloc_array(num_vqs, sizeof(vq_callback_t *),
+                                 GFP_KERNEL);
+       names = kmalloc_array(num_vqs, sizeof(char *), GFP_KERNEL);
 
        if (!callbacks || !vqs || !names) {
                err = -ENOMEM;
index ba3cfa8e279b508fc632147da0aab110e81724ca..a7e94a3decf218510a5cfe0488cd908fecb7c4cc 100644 (file)
@@ -1181,7 +1181,7 @@ static int qman_create_portal(struct qman_portal *portal,
        qm_dqrr_set_ithresh(p, QMAN_PIRQ_DQRR_ITHRESH);
        qm_mr_set_ithresh(p, QMAN_PIRQ_MR_ITHRESH);
        qm_out(p, QM_REG_ITPR, QMAN_PIRQ_IPERIOD);
-       portal->cgrs = kmalloc(2 * sizeof(*cgrs), GFP_KERNEL);
+       portal->cgrs = kmalloc_array(2, sizeof(*cgrs), GFP_KERNEL);
        if (!portal->cgrs)
                goto fail_cgrs;
        /* initial snapshot is no-depletion */
index d2e13fffbc6be8d8b6c9d3be3f4efaaeb7601fac..906c3549e2ba291d2cb327a27fb138b84fea7289 100644 (file)
@@ -941,7 +941,7 @@ static int zoran_open(struct file *file)
        /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
         * on norm-change! */
        fh->overlay_mask =
-           kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL);
+           kmalloc(array3_size((768 + 31) / 32, 576, 4), GFP_KERNEL);
        if (!fh->overlay_mask) {
                dprintk(1,
                        KERN_ERR
index 37a610d05ad2a35d3fa59caafa7a70893ace925e..f2cdcc2bcab48b3a596885f203160804ae423011 100644 (file)
@@ -597,8 +597,9 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
        bool                    bMatchWinStart = false, bPktInBuf = false;
        IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
 
-       prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) *
-                       REORDER_WIN_SIZE, GFP_KERNEL);
+       prxbIndicateArray = kmalloc_array(REORDER_WIN_SIZE,
+                                         sizeof(struct ieee80211_rxb *),
+                                         GFP_KERNEL);
        if (!prxbIndicateArray)
                return;
 
index a4df95cc7f607bccb56a54218156ea816e00bfbb..8b17400f6c13834b7c1fd83200bb371fd2a2172f 100644 (file)
@@ -1640,8 +1640,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
 
-       priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
-                              GFP_KERNEL);
+       priv->rx_urb = kmalloc_array(MAX_RX_URB + 1, sizeof(struct urb *),
+                                    GFP_KERNEL);
        if (!priv->rx_urb)
                return -ENOMEM;
 
index 1db1d97e72e7ee13c8bb1d013dcf5e5ceaf261b4..cb4db1b3ca3c0daab51bbc466789dc5d5bc0710f 100644 (file)
@@ -1441,7 +1441,8 @@ static int hvcs_alloc_index_list(int n)
 {
        int i;
 
-       hvcs_index_list = kmalloc(n * sizeof(hvcs_index_count),GFP_KERNEL);
+       hvcs_index_list = kmalloc_array(n, sizeof(hvcs_index_count),
+                                       GFP_KERNEL);
        if (!hvcs_index_list)
                return -ENOMEM;
        hvcs_index_count = n;
index bdd3027ef01b6d4dbfdf9cd40f2923410cd82a8f..8d96e86966f1b5ddf2bb43067a4899ee1d4653f4 100644 (file)
@@ -1477,7 +1477,7 @@ static int load_firmware(struct pci_dev *pdev,
                        goto errrelfw;
                }
 
-               data = kmalloc(word_count * 2, GFP_KERNEL);
+               data = kmalloc_array(word_count, 2, GFP_KERNEL);
                if (data == NULL) {
                        dev_err(&pdev->dev, "Card%d, firmware upload "
                                "failed, not enough memory\n", index + 1);
index 55b3eff148b18550215087fd1a862edb94ede6f2..8e4428725848eb0e9917af79123442d6ac751cf2 100644 (file)
@@ -2738,8 +2738,9 @@ static int atmel_serial_probe(struct platform_device *pdev)
 
        if (!atmel_use_pdc_rx(&atmel_port->uart)) {
                ret = -ENOMEM;
-               data = kmalloc(sizeof(struct atmel_uart_char)
-                               * ATMEL_SERIAL_RINGSIZE, GFP_KERNEL);
+               data = kmalloc_array(ATMEL_SERIAL_RINGSIZE,
+                                    sizeof(struct atmel_uart_char),
+                                    GFP_KERNEL);
                if (!data)
                        goto err_alloc_ring;
                atmel_port->rx_ring.buf = data;
index 722a6690c70dc74fb3f13892d5c9eead4ed978c0..7c7ada0b3ea00d3b43cf4c12dcccc60257535186 100644 (file)
@@ -231,7 +231,7 @@ static void set_inverse_trans_unicode(struct vc_data *conp,
        q = p->inverse_trans_unicode;
        if (!q) {
                q = p->inverse_trans_unicode =
-                       kmalloc(MAX_GLYPH * sizeof(u16), GFP_KERNEL);
+                       kmalloc_array(MAX_GLYPH, sizeof(u16), GFP_KERNEL);
                if (!q)
                        return;
        }
@@ -479,7 +479,8 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos)
 
        p1 = p->uni_pgdir[n = unicode >> 11];
        if (!p1) {
-               p1 = p->uni_pgdir[n] = kmalloc(32*sizeof(u16 *), GFP_KERNEL);
+               p1 = p->uni_pgdir[n] = kmalloc_array(32, sizeof(u16 *),
+                                                    GFP_KERNEL);
                if (!p1) return -ENOMEM;
                for (i = 0; i < 32; i++)
                        p1[i] = NULL;
@@ -487,7 +488,7 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos)
 
        p2 = p1[n = (unicode >> 6) & 0x1f];
        if (!p2) {
-               p2 = p1[n] = kmalloc(64*sizeof(u16), GFP_KERNEL);
+               p2 = p1[n] = kmalloc_array(64, sizeof(u16), GFP_KERNEL);
                if (!p2) return -ENOMEM;
                memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */
        }
index 5d412df8e94372217726271c7f83e1f55444ae21..d5b4a2b44ab8a69d63f9fe768ac3dffa60d7e9c8 100644 (file)
@@ -1624,7 +1624,7 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
                struct kbdiacr *dia;
                int i;
 
-               dia = kmalloc(MAX_DIACR * sizeof(struct kbdiacr),
+               dia = kmalloc_array(MAX_DIACR, sizeof(struct kbdiacr),
                                                                GFP_KERNEL);
                if (!dia)
                        return -ENOMEM;
@@ -1657,7 +1657,7 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
                struct kbdiacrsuc __user *a = udp;
                void *buf;
 
-               buf = kmalloc(MAX_DIACR * sizeof(struct kbdiacruc),
+               buf = kmalloc_array(MAX_DIACR, sizeof(struct kbdiacruc),
                                                                GFP_KERNEL);
                if (buf == NULL)
                        return -ENOMEM;
index 7851383fbd6c7d7cf567085be5165639b845092a..90ea1cc52b7aac91d6552ce161a16dc4036c3563 100644 (file)
@@ -280,7 +280,8 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
 
        /* Allocate a new buffer before freeing the old one ... */
        multiplier = use_unicode ? 3 : 1;  /* chars can take up to 3 bytes */
-       bp = kmalloc(((sel_end-sel_start)/2+1)*multiplier, GFP_KERNEL);
+       bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
+                          GFP_KERNEL);
        if (!bp) {
                printk(KERN_WARNING "selection: kmalloc() failed\n");
                clear_selection();
index 76e16c5251b9ffe21771e90667184fced5a30867..476dcc5f2da3c3258b2635ab406d09acbd692966 100644 (file)
@@ -897,7 +897,7 @@ static int parse_usbdevfs_streams(struct usb_dev_state *ps,
        if (num_streams_ret && (num_streams < 2 || num_streams > 65536))
                return -EINVAL;
 
-       eps = kmalloc(num_eps * sizeof(*eps), GFP_KERNEL);
+       eps = kmalloc_array(num_eps, sizeof(*eps), GFP_KERNEL);
        if (!eps)
                return -ENOMEM;
 
@@ -1602,8 +1602,9 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
        as->mem_usage = u;
 
        if (num_sgs) {
-               as->urb->sg = kmalloc(num_sgs * sizeof(struct scatterlist),
-                                     GFP_KERNEL);
+               as->urb->sg = kmalloc_array(num_sgs,
+                                           sizeof(struct scatterlist),
+                                           GFP_KERNEL);
                if (!as->urb->sg) {
                        ret = -ENOMEM;
                        goto error;
index 7b137003c2be6a14910b9261d3bab28acc982053..1a15392326fca2354d8ad0dde0d0f6b098890854 100644 (file)
@@ -390,7 +390,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
        }
 
        /* initialize all the urbs we'll use */
-       io->urbs = kmalloc(io->entries * sizeof(*io->urbs), mem_flags);
+       io->urbs = kmalloc_array(io->entries, sizeof(*io->urbs), mem_flags);
        if (!io->urbs)
                goto nomem;
 
@@ -1824,8 +1824,8 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
        n = nintf = 0;
        if (cp) {
                nintf = cp->desc.bNumInterfaces;
-               new_interfaces = kmalloc(nintf * sizeof(*new_interfaces),
-                               GFP_NOIO);
+               new_interfaces = kmalloc_array(nintf, sizeof(*new_interfaces),
+                                              GFP_NOIO);
                if (!new_interfaces)
                        return -ENOMEM;
 
index 3a4e8f616751a85de8cac1632683af6936ac32c9..f3308ce2504389851f2591b2d90a4451ecfcc50f 100644 (file)
@@ -189,7 +189,7 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
                        goto err;
                }
 
-               buff = kmalloc(1028 * sizeof(*buff), GFP_KERNEL);
+               buff = kmalloc_array(1028, sizeof(*buff), GFP_KERNEL);
                if (!buff) {
                        kfree(pkt);
                        err_for = "buffer";
index d3ee1f52aaab2dc42864fb1e3464fa1b8ff4fa4b..4f267dc93882a52579f265e9df0c442e6395531c 100644 (file)
@@ -492,7 +492,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
        char                    *next;
        unsigned                i;
 
-       seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC);
+       seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
        if (!seen)
                return 0;
        seen_count = 0;
index 236a60f53099e042faa9d804f4c470b1d5b90ef1..c2e255f02a72b822b0d4fe996968abff9477fc5a 100644 (file)
@@ -695,7 +695,10 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
                dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
 
        dev->interrupt_in_endpoint_size = usb_endpoint_maxp(dev->interrupt_in_endpoint);
-       dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
+       dev->ring_buffer =
+               kmalloc_array(ring_buffer_size,
+                             sizeof(size_t) + dev->interrupt_in_endpoint_size,
+                             GFP_KERNEL);
        if (!dev->ring_buffer)
                goto error;
        dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
@@ -706,7 +709,9 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
                goto error;
        dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? usb_endpoint_maxp(dev->interrupt_out_endpoint) :
                                                                         udev->descriptor.bMaxPacketSize0;
-       dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
+       dev->interrupt_out_buffer =
+               kmalloc_array(write_buffer_size,
+                             dev->interrupt_out_endpoint_size, GFP_KERNEL);
        if (!dev->interrupt_out_buffer)
                goto error;
        dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
index 62c91e360bafe38e9672abb0df4f100c1ce9cc95..2fb71303ec3ab95b82c6bea40d9604ad4bdc586e 100644 (file)
@@ -736,7 +736,7 @@ static int iuu_uart_on(struct usb_serial_port *port)
        int status;
        u8 *buf;
 
-       buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL);
+       buf = kmalloc(4, GFP_KERNEL);
 
        if (!buf)
                return -ENOMEM;
@@ -790,7 +790,7 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud_base,
        unsigned int T1FrekvensHZ = 0;
 
        dev_dbg(&port->dev, "%s - enter baud_base=%d\n", __func__, baud_base);
-       dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL);
+       dataout = kmalloc(5, GFP_KERNEL);
 
        if (!dataout)
                return -ENOMEM;
index 900591df8bb2432f2760f9b0a245285f09723cbe..6b8edf6178df36907acc98cf51074d3d5f859273 100644 (file)
@@ -1025,7 +1025,7 @@ static int alauda_write_data(struct us_data *us, unsigned long address,
         * We also need a temporary block buffer, where we read in the old data,
         * overwrite parts with the new data, and manipulate the redundancy data
         */
-       blockbuffer = kmalloc((pagesize + 64) * blocksize, GFP_NOIO);
+       blockbuffer = kmalloc_array(pagesize + 64, blocksize, GFP_NOIO);
        if (!blockbuffer) {
                kfree(buffer);
                return USB_STOR_TRANSPORT_ERROR;
index 93cf57ac47d67f07d1c2213f006cf442d4b08dd2..4d261e4de9ad3e5b68060628050f01d842c79d75 100644 (file)
@@ -807,8 +807,12 @@ static int ms_lib_alloc_logicalmap(struct us_data *us)
        u32  i;
        struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
 
-       info->MS_Lib.Phy2LogMap = kmalloc(info->MS_Lib.NumberOfPhyBlock * sizeof(u16), GFP_KERNEL);
-       info->MS_Lib.Log2PhyMap = kmalloc(info->MS_Lib.NumberOfLogBlock * sizeof(u16), GFP_KERNEL);
+       info->MS_Lib.Phy2LogMap = kmalloc_array(info->MS_Lib.NumberOfPhyBlock,
+                                               sizeof(u16),
+                                               GFP_KERNEL);
+       info->MS_Lib.Log2PhyMap = kmalloc_array(info->MS_Lib.NumberOfLogBlock,
+                                               sizeof(u16),
+                                               GFP_KERNEL);
 
        if ((info->MS_Lib.Phy2LogMap == NULL) || (info->MS_Lib.Log2PhyMap == NULL)) {
                ms_lib_free_logicalmap(us);
@@ -1113,8 +1117,12 @@ static int ms_lib_alloc_writebuf(struct us_data *us)
 
        info->MS_Lib.wrtblk = (u16)-1;
 
-       info->MS_Lib.blkpag = kmalloc(info->MS_Lib.PagesPerBlock * info->MS_Lib.BytesPerSector, GFP_KERNEL);
-       info->MS_Lib.blkext = kmalloc(info->MS_Lib.PagesPerBlock * sizeof(struct ms_lib_type_extdat), GFP_KERNEL);
+       info->MS_Lib.blkpag = kmalloc_array(info->MS_Lib.PagesPerBlock,
+                                           info->MS_Lib.BytesPerSector,
+                                           GFP_KERNEL);
+       info->MS_Lib.blkext = kmalloc_array(info->MS_Lib.PagesPerBlock,
+                                           sizeof(struct ms_lib_type_extdat),
+                                           GFP_KERNEL);
 
        if ((info->MS_Lib.blkpag == NULL) || (info->MS_Lib.blkext == NULL)) {
                ms_lib_free_writebuf(us);
index 1cf7dbfe277c4d96ecf3b2ccad15720c5f619659..bc9da736bdfc6998a3bb806f8186e072832951c3 100644 (file)
@@ -1231,8 +1231,8 @@ sddr09_read_map(struct us_data *us) {
 
        kfree(info->lba_to_pba);
        kfree(info->pba_to_lba);
-       info->lba_to_pba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
-       info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
+       info->lba_to_pba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
+       info->pba_to_lba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
 
        if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
                printk(KERN_WARNING "sddr09_read_map: out of memory\n");
index 8c814b2ec9b262289698b8882377d0a58c4553a9..b8527c55335b6e3a977995fa41cc8d7a3337b219 100644 (file)
@@ -651,7 +651,7 @@ static int sddr55_read_map(struct us_data *us) {
 
        numblocks = info->capacity >> (info->blockshift + info->pageshift);
        
-       buffer = kmalloc( numblocks * 2, GFP_NOIO );
+       buffer = kmalloc_array(numblocks, 2, GFP_NOIO );
        
        if (!buffer)
                return -1;
@@ -684,8 +684,8 @@ static int sddr55_read_map(struct us_data *us) {
 
        kfree(info->lba_to_pba);
        kfree(info->pba_to_lba);
-       info->lba_to_pba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
-       info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
+       info->lba_to_pba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
+       info->pba_to_lba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
 
        if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
                kfree(info->lba_to_pba);
index f3e232584284a906309247e5ed5f3c0fef54e472..ad30ddfe30b32297f546a1df939d01085c50009c 100644 (file)
@@ -217,7 +217,7 @@ static
 int uwb_est_grow(void)
 {
        size_t actual_size = uwb_est_size * sizeof(uwb_est[0]);
-       void *new = kmalloc(2 * actual_size, GFP_ATOMIC);
+       void *new = kmalloc_array(2, actual_size, GFP_ATOMIC);
        if (new == NULL)
                return -ENOMEM;
        memcpy(new, uwb_est, actual_size);
index a50cf45e530f7f0dcc76c111da56d919b9f1f1bf..c0430a41e24b9bb1b716d9fbe26ae5978a570b9e 100644 (file)
@@ -376,7 +376,7 @@ int i1480_usb_probe(struct usb_interface *iface, const struct usb_device_id *id)
 
        i1480 = &i1480_usb->i1480;
        i1480->buf_size = 512;
-       i1480->cmd_buf = kmalloc(2 * i1480->buf_size, GFP_KERNEL);
+       i1480->cmd_buf = kmalloc_array(2, i1480->buf_size, GFP_KERNEL);
        if (i1480->cmd_buf == NULL) {
                dev_err(dev, "Cannot allocate transfer buffers\n");
                result = -ENOMEM;
index e7cf7d21cfb5e4e137829123597eb8ff3af6391f..686dc670fd294b3077cf363241338ab871b26244 100644 (file)
@@ -274,8 +274,10 @@ static int vhost_net_set_ubuf_info(struct vhost_net *n)
                zcopy = vhost_net_zcopy_mask & (0x1 << i);
                if (!zcopy)
                        continue;
-               n->vqs[i].ubuf_info = kmalloc(sizeof(*n->vqs[i].ubuf_info) *
-                                             UIO_MAXIOV, GFP_KERNEL);
+               n->vqs[i].ubuf_info =
+                       kmalloc_array(UIO_MAXIOV,
+                                     sizeof(*n->vqs[i].ubuf_info),
+                                     GFP_KERNEL);
                if  (!n->vqs[i].ubuf_info)
                        goto err;
        }
@@ -943,7 +945,7 @@ static int vhost_net_open(struct inode *inode, struct file *f)
        n = kvmalloc(sizeof *n, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
        if (!n)
                return -ENOMEM;
-       vqs = kmalloc(VHOST_NET_VQ_MAX * sizeof(*vqs), GFP_KERNEL);
+       vqs = kmalloc_array(VHOST_NET_VQ_MAX, sizeof(*vqs), GFP_KERNEL);
        if (!vqs) {
                kvfree(n);
                return -ENOMEM;
index 7ad57094d7369278a3f67648bb69f4151fec1fdc..ce10eb75b04240bf88d6a4d5fe8f38c8c74f741d 100644 (file)
@@ -1378,7 +1378,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
                        goto err_vs;
        }
 
-       vqs = kmalloc(VHOST_SCSI_MAX_VQ * sizeof(*vqs), GFP_KERNEL);
+       vqs = kmalloc_array(VHOST_SCSI_MAX_VQ, sizeof(*vqs), GFP_KERNEL);
        if (!vqs)
                goto err_vqs;
 
index 906b8f0f19f7be83f5cff44f8797c6795888454c..40589850eb33c83c06d9211fa86aa95af655dd9e 100644 (file)
@@ -107,7 +107,7 @@ static int vhost_test_open(struct inode *inode, struct file *f)
 
        if (!n)
                return -ENOMEM;
-       vqs = kmalloc(VHOST_TEST_VQ_MAX * sizeof(*vqs), GFP_KERNEL);
+       vqs = kmalloc_array(VHOST_TEST_VQ_MAX, sizeof(*vqs), GFP_KERNEL);
        if (!vqs) {
                kfree(n);
                return -ENOMEM;
index f9bce818da11f39afa7ec20e797a3b491ff6e24b..ce8c95b6365bbe020ed12078c1a7ae0c65c3cd96 100644 (file)
@@ -385,10 +385,13 @@ static long vhost_dev_alloc_iovecs(struct vhost_dev *dev)
 
        for (i = 0; i < dev->nvqs; ++i) {
                vq = dev->vqs[i];
-               vq->indirect = kmalloc(sizeof *vq->indirect * UIO_MAXIOV,
-                                      GFP_KERNEL);
-               vq->log = kmalloc(sizeof *vq->log * UIO_MAXIOV, GFP_KERNEL);
-               vq->heads = kmalloc(sizeof *vq->heads * UIO_MAXIOV, GFP_KERNEL);
+               vq->indirect = kmalloc_array(UIO_MAXIOV,
+                                            sizeof(*vq->indirect),
+                                            GFP_KERNEL);
+               vq->log = kmalloc_array(UIO_MAXIOV, sizeof(*vq->log),
+                                       GFP_KERNEL);
+               vq->heads = kmalloc_array(UIO_MAXIOV, sizeof(*vq->heads),
+                                         GFP_KERNEL);
                if (!vq->indirect || !vq->log || !vq->heads)
                        goto err_nomem;
        }
index bb8971f2a634bc478a97c672ebde8e7d7c7da3cc..a94d700a45030609ac9a01ee1700ab09c1fc20b1 100644 (file)
@@ -191,7 +191,7 @@ static int resize_iovec(struct vringh_kiov *iov, gfp_t gfp)
        if (flag)
                new = krealloc(iov->iov, new_num * sizeof(struct iovec), gfp);
        else {
-               new = kmalloc(new_num * sizeof(struct iovec), gfp);
+               new = kmalloc_array(new_num, sizeof(struct iovec), gfp);
                if (new) {
                        memcpy(new, iov->iov,
                               iov->max_num * sizeof(struct iovec));
index 790900d646c03cf2c96871e9373c367a58edc83e..ca935c09a261c7b5f341b47fe344397b8a9ad3ac 100644 (file)
@@ -269,7 +269,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
        if (attribute) {
                u8 *dst;
 
-               dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
+               dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
                if (!dst)
                        return;
                kfree(ops->cursor_data);
@@ -312,7 +312,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
            vc->vc_cursor_type != ops->p->cursor_shape ||
            ops->cursor_state.mask == NULL ||
            ops->cursor_reset) {
-               char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
+               char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
                int cur_height, size, i = 0;
                u8 msk = 0xff;
 
index 3e330e0f56edc2ba693e3de4e91cd07db8078f7c..c910e74d46ffff43b56c36aae1dedf04494c95af 100644 (file)
@@ -591,7 +591,8 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
                if (scr_readw(r) != vc->vc_video_erase_char)
                        break;
        if (r != q && new_rows >= rows + logo_lines) {
-               save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
+               save = kmalloc(array3_size(logo_lines, new_cols, 2),
+                              GFP_KERNEL);
                if (save) {
                        int i = cols < new_cols ? cols : new_cols;
                        scr_memsetw(save, erase, logo_lines * new_cols * 2);
index 37a8b0b225663780e6e28dd4ba239a6be9581071..dfa9a8aa4509c1705ec2beeda76ff3cf03e60e65 100644 (file)
@@ -258,7 +258,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
        if (attribute) {
                u8 *dst;
 
-               dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
+               dst = kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC);
                if (!dst)
                        return;
                kfree(ops->cursor_data);
@@ -304,14 +304,15 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
            vc->vc_cursor_type != ops->p->cursor_shape ||
            ops->cursor_state.mask == NULL ||
            ops->cursor_reset) {
-               char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
+               char *tmp, *mask = kmalloc_array(w, vc->vc_font.width,
+                                                GFP_ATOMIC);
                int cur_height, size, i = 0;
                int width = (vc->vc_font.width + 7)/8;
 
                if (!mask)
                        return;
 
-               tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
+               tmp = kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC);
 
                if (!tmp) {
                        kfree(mask);
index 1888f8c866e82ecc35571fe9ad35493f0feedef2..ce08251bfd38df4f1c79705a5f64593d1434d667 100644 (file)
@@ -241,7 +241,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
        if (attribute) {
                u8 *dst;
 
-               dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
+               dst = kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC);
                if (!dst)
                        return;
                kfree(ops->cursor_data);
@@ -287,14 +287,15 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
            vc->vc_cursor_type != ops->p->cursor_shape ||
            ops->cursor_state.mask == NULL ||
            ops->cursor_reset) {
-               char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
+               char *tmp, *mask = kmalloc_array(w, vc->vc_font.width,
+                                                GFP_ATOMIC);
                int cur_height, size, i = 0;
                int width = (vc->vc_font.width + 7)/8;
 
                if (!mask)
                        return;
 
-               tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
+               tmp = kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC);
 
                if (!tmp) {
                        kfree(mask);
index 8a51e4d95cc5062ae9efa6c14ac7433de9e668bd..c0d445294aa7c3521e1045480e2636995d93db6c 100644 (file)
@@ -46,7 +46,7 @@ static int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
                info->fbops->fb_sync(info);
 
        if (ops->fd_size < d_cellsize * len) {
-               dst = kmalloc(d_cellsize * len, GFP_KERNEL);
+               dst = kmalloc_array(len, d_cellsize, GFP_KERNEL);
 
                if (dst == NULL) {
                        err = -ENOMEM;
index f98eee263597b08a9677dc8f0072fc62a2cba022..1936afc78fec5ca0b4b8d1cf17c4cc5f92a1538e 100644 (file)
@@ -289,7 +289,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
        if (attribute) {
                u8 *dst;
 
-               dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
+               dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
                if (!dst)
                        return;
                kfree(ops->cursor_data);
@@ -335,7 +335,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
            vc->vc_cursor_type != ops->p->cursor_shape ||
            ops->cursor_state.mask == NULL ||
            ops->cursor_reset) {
-               char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
+               char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
                int cur_height, size, i = 0;
                u8 msk = 0xff;
 
index 924d0730ffe2a80bba32cd36ea41b7d72f357fea..609438d2465b288f831eb086b9d0ef982bb5ddef 100644 (file)
@@ -489,7 +489,8 @@ static int fb_show_logo_line(struct fb_info *info, int rotate,
        }
 
        if (fb_logo.depth <= 4) {
-               logo_new = kmalloc(logo->width * logo->height, GFP_KERNEL);
+               logo_new = kmalloc_array(logo->width, logo->height,
+                                        GFP_KERNEL);
                if (logo_new == NULL) {
                        kfree(palette);
                        if (saved_pseudo_palette)
@@ -506,8 +507,8 @@ static int fb_show_logo_line(struct fb_info *info, int rotate,
        image.height = logo->height;
 
        if (rotate) {
-               logo_rotate = kmalloc(logo->width *
-                                     logo->height, GFP_KERNEL);
+               logo_rotate = kmalloc_array(logo->width, logo->height,
+                                           GFP_KERNEL);
                if (logo_rotate)
                        fb_rotate_logo(info, logo_rotate, &image, rotate);
        }
index 2b2d673285148bc4dba1eb24c8d0d18f4d8b6a01..522cf441842c08af3ac527e7e0ca9e564db723d2 100644 (file)
@@ -671,7 +671,7 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize,
        }
 
        *dbsize = num;
-       m = kmalloc(num * sizeof(struct fb_videomode), GFP_KERNEL);
+       m = kmalloc_array(num, sizeof(struct fb_videomode), GFP_KERNEL);
        if (!m)
                return mode;
        memmove(m, mode, num * sizeof(struct fb_videomode));
index ba82f97fb42b2d10fdbebd227fcb7e5eb19dcbdc..c4eb8661f7516d965d3a988400ce10730a181a4e 100644 (file)
@@ -662,7 +662,7 @@ static int imxfb_init_fbinfo(struct platform_device *pdev)
 
        pr_debug("%s\n",__func__);
 
-       info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
+       info->pseudo_palette = kmalloc_array(16, sizeof(u32), GFP_KERNEL);
        if (!info->pseudo_palette)
                return -ENOMEM;
 
index fe92eed6da70c01bb1a96b07c23f87561d5dac18..8dd296d257ddd61a165a229f892fd1d6c2ad9974 100644 (file)
@@ -245,7 +245,7 @@ static void mb86290fb_imageblit(struct fb_info *info,
                return;
        }
 
-       cmd = kmalloc(cmdlen * 4, GFP_DMA);
+       cmd = kmalloc_array(cmdlen, 4, GFP_DMA);
        if (!cmd)
                return cfb_imageblit(info, image);
        cmdfn(cmd, step, dx, dy, width, height, fgcolor, bgcolor, image, info);
index 418a2d0d06a95b7005472983f386a75bc4426abf..2e50120bcfae10431bdf2cfb576a43e3b7391fd6 100644 (file)
@@ -566,7 +566,7 @@ static int nvidiafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
                u8 *msk = (u8 *) cursor->mask;
                u8 *src;
 
-               src = kmalloc(s_pitch * cursor->image.height, GFP_ATOMIC);
+               src = kmalloc_array(s_pitch, cursor->image.height, GFP_ATOMIC);
 
                if (src) {
                        switch (cursor->rop) {
index a582d3ae7ac1d6812bd6c736160c94ecf4c7d5e4..8a53d1de611d5cdd99f58ddbef03ca8ba73dcc09 100644 (file)
@@ -682,7 +682,7 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
 
        nr_pages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-       pages = kmalloc(nr_pages * sizeof(struct page *), GFP_KERNEL);
+       pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
        if (!pages)
                return -ENOMEM;
 
index ff8282374f37b098f2bf1e1d211eae4bae201b16..cc242ba057d3ea0dcf613ea17246c3a2a683c127 100644 (file)
@@ -1615,7 +1615,7 @@ static int rivafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
                u8 *msk = (u8 *) cursor->mask;
                u8 *src;
                
-               src = kmalloc(s_pitch * cursor->image.height, GFP_ATOMIC);
+               src = kmalloc_array(s_pitch, cursor->image.height, GFP_ATOMIC);
 
                if (src) {
                        switch (cursor->rop) {
index 9b45125988fbcab1af7a77a7bcddb74e1b6fd725..52f577b0669b00a737168d117483c3cc9a9beac9 100644 (file)
@@ -596,7 +596,8 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
                break;
 
        case VIAFB_GET_GAMMA_LUT:
-               viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
+               viafb_gamma_table = kmalloc_array(256, sizeof(u32),
+                                                 GFP_KERNEL);
                if (!viafb_gamma_table)
                        return -ENOMEM;
                viafb_get_gamma_table(viafb_gamma_table);
index 035ff6e0289496df8f00712785237be418fa4ecd..696106ecdff07c93268c7c3f8092b54317b95b00 100644 (file)
@@ -693,7 +693,8 @@ int w100fb_probe(struct platform_device *pdev)
                goto out;
        }
 
-       info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL);
+       info->pseudo_palette = kmalloc_array(MAX_PALETTES, sizeof(u32),
+                                            GFP_KERNEL);
        if (!info->pseudo_palette) {
                err = -ENOMEM;
                goto out;
index 2f3856a95856be43bcbfc6a4c3865f7099045368..3093655c7b92718b9c384f2f9791c221eaf258ab 100644 (file)
@@ -69,7 +69,7 @@ static void vbg_guest_mappings_init(struct vbg_dev *gdev)
        /* Add 4M so that we can align the vmap to 4MiB as the host requires. */
        size = PAGE_ALIGN(req->hypervisor_size) + SZ_4M;
 
-       pages = kmalloc(sizeof(*pages) * (size >> PAGE_SHIFT), GFP_KERNEL);
+       pages = kmalloc_array(size >> PAGE_SHIFT, sizeof(*pages), GFP_KERNEL);
        if (!pages)
                goto out;
 
@@ -262,8 +262,9 @@ static int vbg_balloon_inflate(struct vbg_dev *gdev, u32 chunk_idx)
        struct page **pages;
        int i, rc, ret;
 
-       pages = kmalloc(sizeof(*pages) * VMMDEV_MEMORY_BALLOON_CHUNK_PAGES,
-                       GFP_KERNEL | __GFP_NOWARN);
+       pages = kmalloc_array(VMMDEV_MEMORY_BALLOON_CHUNK_PAGES,
+                             sizeof(*pages),
+                             GFP_KERNEL | __GFP_NOWARN);
        if (!pages)
                return -ENOMEM;
 
index 48d4d1cf1cb63f7b67f58f17e3d7874d14a00b09..a491d0ed3f16a4b1fb2ba7aa5078f087614aa50b 100644 (file)
@@ -113,8 +113,9 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 
        vp_dev->msix_vectors = nvectors;
 
-       vp_dev->msix_names = kmalloc(nvectors * sizeof *vp_dev->msix_names,
-                                    GFP_KERNEL);
+       vp_dev->msix_names = kmalloc_array(nvectors,
+                                          sizeof(*vp_dev->msix_names),
+                                          GFP_KERNEL);
        if (!vp_dev->msix_names)
                goto error;
        vp_dev->msix_affinity_masks
index 21d464a29cf8d637db6ccff38e2c146b4296c4d4..814b395007b2c35e694519c173d47143f12e277b 100644 (file)
@@ -247,7 +247,7 @@ static struct vring_desc *alloc_indirect(struct virtqueue *_vq,
         */
        gfp &= ~__GFP_HIGHMEM;
 
-       desc = kmalloc(total_sg * sizeof(struct vring_desc), gfp);
+       desc = kmalloc_array(total_sg, sizeof(struct vring_desc), gfp);
        if (!desc)
                return NULL;
 
index 27be107d648020a1faf69f2feb3ee118f884411f..2473b0a9e6e41d5d51b47e318d7e3b26d81ec5f6 100644 (file)
@@ -1137,7 +1137,7 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
        /* No need for kzalloc as it is initialized in following hypercall
         * GNTTABOP_setup_table.
         */
-       frames = kmalloc(nr_gframes * sizeof(unsigned long), GFP_ATOMIC);
+       frames = kmalloc_array(nr_gframes, sizeof(unsigned long), GFP_ATOMIC);
        if (!frames)
                return -ENOMEM;
 
@@ -1300,8 +1300,9 @@ int gnttab_init(void)
        max_nr_glist_frames = (max_nr_grant_frames *
                               gnttab_interface->grefs_per_grant_frame / RPP);
 
-       gnttab_list = kmalloc(max_nr_glist_frames * sizeof(grant_ref_t *),
-                             GFP_KERNEL);
+       gnttab_list = kmalloc_array(max_nr_glist_frames,
+                                   sizeof(grant_ref_t *),
+                                   GFP_KERNEL);
        if (gnttab_list == NULL)
                return -ENOMEM;
 
index ee2c891b55c6bf46e97e6e529f65e478a12e7c3e..ea4a08b83fa099ae04ed8486a6cff98a602f1e57 100644 (file)
@@ -234,7 +234,7 @@ int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,
        if (dev->msi_enabled || !(cmd & PCI_COMMAND_MEMORY))
                return -ENXIO;
 
-       entries = kmalloc(op->value * sizeof(*entries), GFP_KERNEL);
+       entries = kmalloc_array(op->value, sizeof(*entries), GFP_KERNEL);
        if (entries == NULL)
                return -ENOMEM;
 
index ed4f8519b6270656b1e1c899cdf31dd4d451ded8..a9ef46f02354f465ca013ff048b4591b928bade6 100644 (file)
@@ -100,7 +100,7 @@ static int build_path_from_dentry(struct v9fs_session_info *v9ses,
        for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
                n++;
 
-       wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL);
+       wnames = kmalloc_array(n, sizeof(char *), GFP_KERNEL);
        if (!wnames)
                goto err_out;
 
index cfda2c7caedcec8b53d738f7c93924a723515370..71fa525d63a06c5f3b4196ddad6dcea517c4f4da 100644 (file)
@@ -313,7 +313,7 @@ static struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_di
 
        asb->s_ids_per_zone = zone_size / (asb->s_idlen + 1);
 
-       dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL);
+       dm = kmalloc_array(nzones, sizeof(*dm), GFP_KERNEL);
        if (dm == NULL) {
                adfs_error(sb, "not enough memory");
                return ERR_PTR(-ENOMEM);
index c332c95a6940f50fe3a9e220ebbb6928b0f5d27c..238fd28cfdd2cabae2fbf1530ed923be387c5517 100644 (file)
@@ -191,7 +191,8 @@ static int afs_deliver_cb_callback(struct afs_call *call)
                if (call->count > AFSCBMAX)
                        return afs_protocol_error(call, -EBADMSG);
 
-               call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
+               call->buffer = kmalloc(array3_size(call->count, 3, 4),
+                                      GFP_KERNEL);
                if (!call->buffer)
                        return -ENOMEM;
                call->offset = 0;
@@ -330,7 +331,7 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
        switch (call->unmarshall) {
        case 0:
                call->offset = 0;
-               call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
+               call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
                if (!call->buffer)
                        return -ENOMEM;
                call->unmarshall++;
@@ -453,7 +454,7 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)
        switch (call->unmarshall) {
        case 0:
                call->offset = 0;
-               call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
+               call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
                if (!call->buffer)
                        return -ENOMEM;
                call->unmarshall++;
index 4ad6f669fe34b21ec592cdd25b7b284fb0f74398..bf5ee6f741cd5404ca8eab4cce0dbc38657773c6 100644 (file)
@@ -2010,7 +2010,7 @@ static int elf_note_info_init(struct elf_note_info *info)
        INIT_LIST_HEAD(&info->thread_list);
 
        /* Allocate space for ELF notes */
-       info->notes = kmalloc(8 * sizeof(struct memelfnote), GFP_KERNEL);
+       info->notes = kmalloc_array(8, sizeof(struct memelfnote), GFP_KERNEL);
        if (!info->notes)
                return 0;
        info->psinfo = kmalloc(sizeof(*info->psinfo), GFP_KERNEL);
index d90993adeffa3d19186bcb50aeb85110bf971a7f..b53bb3729ac1ef91e7105cea04b7a27d1e4553f8 100644 (file)
@@ -1600,7 +1600,8 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
        psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
        if (!psinfo)
                goto cleanup;
-       notes = kmalloc(NUM_NOTES * sizeof(struct memelfnote), GFP_KERNEL);
+       notes = kmalloc_array(NUM_NOTES, sizeof(struct memelfnote),
+                             GFP_KERNEL);
        if (!notes)
                goto cleanup;
        fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
index 05e12aea24043dac01826bcc833be0e9e8c2e13b..0dd87aaeb39a7d05bbec28ce01536b106c4f76c2 100644 (file)
@@ -205,7 +205,8 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
        if (nr_pages <= DIO_INLINE_BIO_VECS)
                vecs = inline_vecs;
        else {
-               vecs = kmalloc(nr_pages * sizeof(struct bio_vec), GFP_KERNEL);
+               vecs = kmalloc_array(nr_pages, sizeof(struct bio_vec),
+                                    GFP_KERNEL);
                if (!vecs)
                        return -ENOMEM;
        }
index 5f7ad3d0df2ea69121acded120e26d05515fd79a..c9cb2f33a6d6763f1abcce330186775d7e99eb0b 100644 (file)
@@ -370,7 +370,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
 
        /* build page vector */
        nr_pages = calc_pages_for(0, len);
-       pages = kmalloc(sizeof(*pages) * nr_pages, GFP_KERNEL);
+       pages = kmalloc_array(nr_pages, sizeof(*pages), GFP_KERNEL);
        if (!pages) {
                ret = -ENOMEM;
                goto out_put;
@@ -966,8 +966,9 @@ get_more_pages:
 
                                BUG_ON(pages);
                                max_pages = calc_pages_for(0, (u64)len);
-                               pages = kmalloc(max_pages * sizeof (*pages),
-                                               GFP_NOFS);
+                               pages = kmalloc_array(max_pages,
+                                                     sizeof(*pages),
+                                                     GFP_NOFS);
                                if (!pages) {
                                        pool = fsc->wb_pagevec_pool;
                                        pages = mempool_alloc(pool, GFP_NOFS);
@@ -1113,8 +1114,8 @@ new_request:
 
                        /* allocate new pages array for next request */
                        data_pages = pages;
-                       pages = kmalloc(locked_pages * sizeof (*pages),
-                                       GFP_NOFS);
+                       pages = kmalloc_array(locked_pages, sizeof(*pages),
+                                             GFP_NOFS);
                        if (!pages) {
                                pool = fsc->wb_pagevec_pool;
                                pages = mempool_alloc(pool, GFP_NOFS);
index 5ece2e6ad1548e0893ee9734132a64bb66ffc89e..cf8d24812cc00e0d01ebc991476298975498e2d9 100644 (file)
@@ -2992,8 +2992,9 @@ encode_again:
                        num_flock_locks = 0;
                }
                if (num_fcntl_locks + num_flock_locks > 0) {
-                       flocks = kmalloc((num_fcntl_locks + num_flock_locks) *
-                                        sizeof(struct ceph_filelock), GFP_NOFS);
+                       flocks = kmalloc_array(num_fcntl_locks + num_flock_locks,
+                                              sizeof(struct ceph_filelock),
+                                              GFP_NOFS);
                        if (!flocks) {
                                err = -ENOMEM;
                                goto out_free;
index a3b56544c21b96599fa97f0df02a5fd2c6317678..3d19595eb35216a8c32501d34200fa8061cff512 100644 (file)
@@ -428,7 +428,7 @@ asn1_oid_decode(struct asn1_ctx *ctx,
        if (size < 2 || size > UINT_MAX/sizeof(unsigned long))
                return 0;
 
-       *oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC);
+       *oid = kmalloc_array(size, sizeof(unsigned long), GFP_ATOMIC);
        if (*oid == NULL)
                return 0;
 
index 13a8a77322c98f3e17e3b53bd689e95fc0ee3ffe..1d377b7f286055fa0b8c2117c89f843704fb9c3c 100644 (file)
@@ -747,8 +747,8 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
 
                if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))
                        return;
-               ppace = kmalloc(num_aces * sizeof(struct cifs_ace *),
-                               GFP_KERNEL);
+               ppace = kmalloc_array(num_aces, sizeof(struct cifs_ace *),
+                                     GFP_KERNEL);
                if (!ppace)
                        return;
 
index 745fd7fe8d0ef595ade32f79ea6e1dcb60b32c9e..a94071c7b4089076d35a82ae38c24bbe62a50a91 100644 (file)
@@ -1792,7 +1792,7 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry,
                 * with unix extensions enabled.
                 */
                info_buf_source =
-                       kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO),
+                       kmalloc_array(2, sizeof(FILE_UNIX_BASIC_INFO),
                                        GFP_KERNEL);
                if (info_buf_source == NULL) {
                        rc = -ENOMEM;
index 48e2004c75fb447671ad695e6abd756b888303fa..af032e1a3eac7adaf0570f5923e0ba6164e8ed6b 100644 (file)
@@ -3471,7 +3471,7 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
        if (!num)
                return -EINVAL;
 
-       iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL);
+       iov = kmalloc_array(num, sizeof(struct kvec), GFP_KERNEL);
        if (!iov)
                return -ENOMEM;
 
@@ -3535,7 +3535,7 @@ SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
        int rc;
        int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
 
-       data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
+       data = kmalloc_array(2, sizeof(void *), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
@@ -3583,7 +3583,7 @@ SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
        int rc;
        int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
 
-       data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
+       data = kmalloc_array(2, sizeof(void *), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
index 24887a0898c05dbc92f59d4034d7a2c1a9a0d382..1f1a68f8911001bae86976171e44a09402982d92 100644 (file)
@@ -844,8 +844,8 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
        int rc;
 
        if (n_vec + 1 > CIFS_MAX_IOV_SIZE) {
-               new_iov = kmalloc(sizeof(struct kvec) * (n_vec + 1),
-                                 GFP_KERNEL);
+               new_iov = kmalloc_array(n_vec + 1, sizeof(struct kvec),
+                                       GFP_KERNEL);
                if (!new_iov) {
                        /* otherwise cifs_send_recv below sets resp_buf_type */
                        *resp_buf_type = CIFS_NO_BUFFER;
@@ -886,8 +886,8 @@ smb2_send_recv(const unsigned int xid, struct cifs_ses *ses,
        __be32 rfc1002_marker;
 
        if (n_vec + 1 > CIFS_MAX_IOV_SIZE) {
-               new_iov = kmalloc(sizeof(struct kvec) * (n_vec + 1),
-                                 GFP_KERNEL);
+               new_iov = kmalloc_array(n_vec + 1, sizeof(struct kvec),
+                                       GFP_KERNEL);
                if (!new_iov)
                        return -ENOMEM;
        } else
index 0ac62811b34118ab4889d4ee8807706818efadff..5f81fcd383a4d42c2887b01bbd467251f220d7e3 100644 (file)
@@ -110,8 +110,8 @@ static int pcol_try_alloc(struct page_collect *pcol)
        pages =  exofs_max_io_pages(&pcol->sbi->layout, pcol->expected_pages);
 
        for (; pages; pages >>= 1) {
-               pcol->pages = kmalloc(pages * sizeof(struct page *),
-                                     GFP_KERNEL);
+               pcol->pages = kmalloc_array(pages, sizeof(struct page *),
+                                           GFP_KERNEL);
                if (likely(pcol->pages)) {
                        pcol->alloc_pages = pages;
                        return 0;
index c09289a42dc553df2fdc9658faed3ceb463714fb..25ab1274090f8532254e783def084bccd24a21c4 100644 (file)
@@ -1082,7 +1082,9 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
                                        / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
        db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
                   EXT2_DESC_PER_BLOCK(sb);
-       sbi->s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
+       sbi->s_group_desc = kmalloc_array (db_count,
+                                          sizeof(struct buffer_head *),
+                                          GFP_KERNEL);
        if (sbi->s_group_desc == NULL) {
                ext2_msg(sb, KERN_ERR, "error: not enough memory");
                goto failed_mount;
index d792b7689d92c23234cbc6d3158d75d307d8ba3b..e5fb38451a733cc947a5c9f77c478545b5699013 100644 (file)
@@ -204,12 +204,14 @@ static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
                goto out2;
        flex_gd->count = flexbg_size;
 
-       flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) *
-                                 flexbg_size, GFP_NOFS);
+       flex_gd->groups = kmalloc_array(flexbg_size,
+                                       sizeof(struct ext4_new_group_data),
+                                       GFP_NOFS);
        if (flex_gd->groups == NULL)
                goto out2;
 
-       flex_gd->bg_flags = kmalloc(flexbg_size * sizeof(__u16), GFP_NOFS);
+       flex_gd->bg_flags = kmalloc_array(flexbg_size, sizeof(__u16),
+                                         GFP_NOFS);
        if (flex_gd->bg_flags == NULL)
                goto out1;
 
@@ -969,7 +971,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
        int res, i;
        int err;
 
-       primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_NOFS);
+       primary = kmalloc_array(reserved_gdb, sizeof(*primary), GFP_NOFS);
        if (!primary)
                return -ENOMEM;
 
index 4f4362d5a04c4c5283fec23fa703440e12da8d49..d4e23f8ddcf6e30f065a9417da16e4c0cfcba4ca 100644 (file)
@@ -664,7 +664,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
        if (len == 0)
                return -ENOENT;
 
-       slots = kmalloc(sizeof(*slots) * MSDOS_SLOTS, GFP_NOFS);
+       slots = kmalloc_array(MSDOS_SLOTS, sizeof(*slots), GFP_NOFS);
        if (slots == NULL)
                return -ENOMEM;
 
index e03ca14f40e957703ad901e83c2f6ec90f46fc56..c6b88fa85e2e5d048ea49b268c402843d53c2c0e 100644 (file)
@@ -64,9 +64,12 @@ static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
                        pages = req->inline_pages;
                        page_descs = req->inline_page_descs;
                } else {
-                       pages = kmalloc(sizeof(struct page *) * npages, flags);
-                       page_descs = kmalloc(sizeof(struct fuse_page_desc) *
-                                            npages, flags);
+                       pages = kmalloc_array(npages, sizeof(struct page *),
+                                             flags);
+                       page_descs =
+                               kmalloc_array(npages,
+                                             sizeof(struct fuse_page_desc),
+                                             flags);
                }
 
                if (!pages || !page_descs) {
@@ -1359,7 +1362,8 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
        if (!fud)
                return -EPERM;
 
-       bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
+       bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
+                            GFP_KERNEL);
        if (!bufs)
                return -ENOMEM;
 
@@ -1940,7 +1944,8 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
        if (!fud)
                return -EPERM;
 
-       bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
+       bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
+                            GFP_KERNEL);
        if (!bufs)
                return -ENOMEM;
 
index d9fb0ad6cc30cc92c32e22b1c86ea056cad732b7..3090c445e8fc845ea4c343c4468577920d8f159f 100644 (file)
@@ -1055,7 +1055,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
        /* Change the pointers.
           Don't bother distinguishing stuffed from non-stuffed.
           This code is complicated enough already. */
-       lp = kmalloc(half_len * sizeof(__be64), GFP_NOFS);
+       lp = kmalloc_array(half_len, sizeof(__be64), GFP_NOFS);
        if (!lp) {
                error = -ENOMEM;
                goto fail_brelse;
@@ -1169,7 +1169,7 @@ static int dir_double_exhash(struct gfs2_inode *dip)
        if (IS_ERR(hc))
                return PTR_ERR(hc);
 
-       hc2 = kmalloc(hsize_bytes * 2, GFP_NOFS | __GFP_NOWARN);
+       hc2 = kmalloc_array(hsize_bytes, 2, GFP_NOFS | __GFP_NOWARN);
        if (hc2 == NULL)
                hc2 = __vmalloc(hsize_bytes * 2, GFP_NOFS, PAGE_KERNEL);
 
@@ -1596,7 +1596,7 @@ int gfs2_dir_read(struct inode *inode, struct dir_context *ctx,
 
        error = -ENOMEM;
        /* 96 is max number of dirents which can be stuffed into an inode */
-       darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_NOFS);
+       darr = kmalloc_array(96, sizeof(struct gfs2_dirent *), GFP_NOFS);
        if (darr) {
                g.pdent = (const struct gfs2_dirent **)darr;
                g.offset = 0;
index 097bd3c0f270b690d9e74c9c053698568a03fef9..4614ee25f6211efe24550edfdd68021ceaa20bf7 100644 (file)
@@ -1303,7 +1303,8 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs)
        default:
                if (num_gh <= 4)
                        break;
-               pph = kmalloc(num_gh * sizeof(struct gfs2_holder *), GFP_NOFS);
+               pph = kmalloc_array(num_gh, sizeof(struct gfs2_holder *),
+                                   GFP_NOFS);
                if (!pph)
                        return -ENOMEM;
        }
index e8585dfd209f5b8174b6fb8d892de7b4e28270fe..0efae7a0ee8017a41754e9bf51f013e1e20971ef 100644 (file)
@@ -886,7 +886,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
        gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
                              &data_blocks, &ind_blocks);
 
-       ghs = kmalloc(num_qd * sizeof(struct gfs2_holder), GFP_NOFS);
+       ghs = kmalloc_array(num_qd, sizeof(struct gfs2_holder), GFP_NOFS);
        if (!ghs)
                return -ENOMEM;
 
index 6bc5cfe710d18fc1e7bf6a0550a1a032593e0ccb..33abcf29bc05c4c80114203a05958240c085198b 100644 (file)
@@ -2605,8 +2605,9 @@ void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state)
 {
        unsigned int x;
 
-       rlist->rl_ghs = kmalloc(rlist->rl_rgrps * sizeof(struct gfs2_holder),
-                               GFP_NOFS | __GFP_NOFAIL);
+       rlist->rl_ghs = kmalloc_array(rlist->rl_rgrps,
+                                     sizeof(struct gfs2_holder),
+                                     GFP_NOFS | __GFP_NOFAIL);
        for (x = 0; x < rlist->rl_rgrps; x++)
                gfs2_holder_init(rlist->rl_rgd[x]->rd_gl,
                                state, 0,
index cf5c7f3080d24502218a4a3dadd776c61de7d1cd..af0d5b01cf0bfcc1963e4f671d080102d65edfe2 100644 (file)
@@ -1097,7 +1097,7 @@ static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host
        int error = 0, err;
 
        memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
-       gha = kmalloc(slots * sizeof(struct gfs2_holder), GFP_KERNEL);
+       gha = kmalloc_array(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
        if (!gha)
                return -ENOMEM;
        for (x = 0; x < slots; x++)
index a4ad18afbdec7ffba2eb5cd46c59879433ba6da9..4ada525c5c43781aeb5060455c01d5c2511fd368 100644 (file)
@@ -33,7 +33,8 @@ int hpfs_add_pos(struct inode *inode, loff_t *pos)
                        if (hpfs_inode->i_rddir_off[i] == pos)
                                return 0;
        if (!(i&0x0f)) {
-               if (!(ppos = kmalloc((i+0x11) * sizeof(loff_t*), GFP_NOFS))) {
+               ppos = kmalloc_array(i + 0x11, sizeof(loff_t *), GFP_NOFS);
+               if (!ppos) {
                        pr_err("out of memory for position list\n");
                        return -ENOMEM;
                }
index 7c49f1ef0c850320b351397e0c1f2d93f267131a..ecd9fccd166316b10f54f2919cee01762b0cfbfd 100644 (file)
@@ -115,7 +115,7 @@ __le32 *hpfs_load_bitmap_directory(struct super_block *s, secno bmp)
        int n = (hpfs_sb(s)->sb_fs_size + 0x200000 - 1) >> 21;
        int i;
        __le32 *b;
-       if (!(b = kmalloc(n * 512, GFP_KERNEL))) {
+       if (!(b = kmalloc_array(n, 512, GFP_KERNEL))) {
                pr_err("can't allocate memory for bitmap directory\n");
                return NULL;
        }       
index 240779e4689c53f0705615ee4d39d2096f9854b0..a1143e57a718ee20c83b0c813fb13425beff2d16 100644 (file)
@@ -223,7 +223,7 @@ static struct jbd2_revoke_table_s *jbd2_journal_init_revoke_table(int hash_size)
        table->hash_size = hash_size;
        table->hash_shift = shift;
        table->hash_table =
-               kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
+               kmalloc_array(hash_size, sizeof(struct list_head), GFP_KERNEL);
        if (!table->hash_table) {
                kmem_cache_free(jbd2_revoke_table_cache, table);
                table = NULL;
index 2cfe487708e08f268c166053927eafec9c68eac6..c6821a5094818a48030697b95178241304905d28 100644 (file)
@@ -1208,7 +1208,7 @@ int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
        if (!c->wbuf)
                return -ENOMEM;
 
-       c->oobbuf = kmalloc(NR_OOB_SCAN_PAGES * c->oobavail, GFP_KERNEL);
+       c->oobbuf = kmalloc_array(NR_OOB_SCAN_PAGES, c->oobavail, GFP_KERNEL);
        if (!c->oobbuf) {
                kfree(c->wbuf);
                return -ENOMEM;
index 2d514c7affc2ab9382fa812bc173874f3b58b8e9..49263e220dbcf3add3b1cd624a1b8709af955c8e 100644 (file)
@@ -1641,7 +1641,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
        max_ranges = nblocks;
        do_div(max_ranges, minlen);
        range_cnt = min_t(u64, max_ranges + 1, 32 * 1024);
-       totrim = kmalloc(sizeof(struct range2trim) * range_cnt, GFP_NOFS);
+       totrim = kmalloc_array(range_cnt, sizeof(struct range2trim), GFP_NOFS);
        if (totrim == NULL) {
                jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n");
                IWRITE_UNLOCK(ipbmap);
index de2bcb36e0793915e28bd65e1c7e6f6b02514402..52bae3f5c9145df968a3803ee2f7cad0b5fe4bf7 100644 (file)
@@ -594,7 +594,8 @@ int dtSearch(struct inode *ip, struct component_name * key, ino_t * data,
        struct component_name ciKey;
        struct super_block *sb = ip->i_sb;
 
-       ciKey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t), GFP_NOFS);
+       ciKey.name = kmalloc_array(JFS_NAME_MAX + 1, sizeof(wchar_t),
+                                  GFP_NOFS);
        if (!ciKey.name) {
                rc = -ENOMEM;
                goto dtSearch_Exit2;
@@ -957,7 +958,7 @@ static int dtSplitUp(tid_t tid,
        smp = split->mp;
        sp = DT_PAGE(ip, smp);
 
-       key.name = kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t), GFP_NOFS);
+       key.name = kmalloc_array(JFS_NAME_MAX + 2, sizeof(wchar_t), GFP_NOFS);
        if (!key.name) {
                DT_PUTPAGE(smp);
                rc = -ENOMEM;
@@ -3779,12 +3780,12 @@ static int ciGetLeafPrefixKey(dtpage_t * lp, int li, dtpage_t * rp,
        struct component_name lkey;
        struct component_name rkey;
 
-       lkey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
+       lkey.name = kmalloc_array(JFS_NAME_MAX + 1, sizeof(wchar_t),
                                        GFP_KERNEL);
        if (lkey.name == NULL)
                return -ENOMEM;
 
-       rkey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
+       rkey.name = kmalloc_array(JFS_NAME_MAX + 1, sizeof(wchar_t),
                                        GFP_KERNEL);
        if (rkey.name == NULL) {
                kfree(lkey.name);
index c7de6f5bbefc1da43b269ffe54ddec707ba7b0a1..0148e2e4d97ac66e826ad5ddfb5cf32b20258468 100644 (file)
@@ -121,7 +121,7 @@ int get_UCSname(struct component_name * uniName, struct dentry *dentry)
                return -ENAMETOOLONG;
 
        uniName->name =
-           kmalloc((length + 1) * sizeof(wchar_t), GFP_NOFS);
+           kmalloc_array(length + 1, sizeof(wchar_t), GFP_NOFS);
 
        if (uniName->name == NULL)
                return -ENOMEM;
index bf41e2e72c1883b7fba884a8f7006ecc50bcf768..081ccf0caee35966477d8a2b801c19051fd2faf9 100644 (file)
@@ -353,8 +353,9 @@ struct mb_cache *mb_cache_create(int bucket_bits)
        cache->c_max_entries = bucket_count << 4;
        INIT_LIST_HEAD(&cache->c_list);
        spin_lock_init(&cache->c_list_lock);
-       cache->c_hash = kmalloc(bucket_count * sizeof(struct hlist_bl_head),
-                               GFP_KERNEL);
+       cache->c_hash = kmalloc_array(bucket_count,
+                                     sizeof(struct hlist_bl_head),
+                                     GFP_KERNEL);
        if (!cache->c_hash) {
                kfree(cache);
                goto err_out;
index 6df1f61855d600a7072b2b770e993118cc5ac036..2490ddb8bc90ca5c7dfcf406d50d374977a71846 100644 (file)
@@ -537,12 +537,12 @@ static int __nd_alloc_stack(struct nameidata *nd)
        struct saved *p;
 
        if (nd->flags & LOOKUP_RCU) {
-               p= kmalloc(MAXSYMLINKS * sizeof(struct saved),
+               p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
                                  GFP_ATOMIC);
                if (unlikely(!p))
                        return -ECHILD;
        } else {
-               p= kmalloc(MAXSYMLINKS * sizeof(struct saved),
+               p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
                                  GFP_KERNEL);
                if (unlikely(!p))
                        return -ENOMEM;
index 66eaeb1e8c2ce75559d4b03c36ab7a16bda56af5..9c247fa1e95940564857fd585a7a539f64a3a977 100644 (file)
@@ -510,8 +510,9 @@ nfs4_legacy_state_init(struct net *net)
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        int i;
 
-       nn->reclaim_str_hashtbl = kmalloc(sizeof(struct list_head) *
-                                         CLIENT_HASH_SIZE, GFP_KERNEL);
+       nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
+                                               sizeof(struct list_head),
+                                               GFP_KERNEL);
        if (!nn->reclaim_str_hashtbl)
                return -ENOMEM;
 
index fc74d6f46bd5d17a2adf89a4d2ddc80f9e5c44cd..39370a503a6313233bf75732519ab9c76bb652ec 100644 (file)
@@ -1807,8 +1807,9 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
        clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
        if (clp->cl_name.data == NULL)
                goto err_no_name;
-       clp->cl_ownerstr_hashtbl = kmalloc(sizeof(struct list_head) *
-                       OWNER_HASH_SIZE, GFP_KERNEL);
+       clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE,
+                                                sizeof(struct list_head),
+                                                GFP_KERNEL);
        if (!clp->cl_ownerstr_hashtbl)
                goto err_no_hashtbl;
        for (i = 0; i < OWNER_HASH_SIZE; i++)
@@ -7093,16 +7094,19 @@ static int nfs4_state_create_net(struct net *net)
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        int i;
 
-       nn->conf_id_hashtbl = kmalloc(sizeof(struct list_head) *
-                       CLIENT_HASH_SIZE, GFP_KERNEL);
+       nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
+                                           sizeof(struct list_head),
+                                           GFP_KERNEL);
        if (!nn->conf_id_hashtbl)
                goto err;
-       nn->unconf_id_hashtbl = kmalloc(sizeof(struct list_head) *
-                       CLIENT_HASH_SIZE, GFP_KERNEL);
+       nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
+                                             sizeof(struct list_head),
+                                             GFP_KERNEL);
        if (!nn->unconf_id_hashtbl)
                goto err_unconf_id;
-       nn->sessionid_hashtbl = kmalloc(sizeof(struct list_head) *
-                       SESSION_HASH_SIZE, GFP_KERNEL);
+       nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE,
+                                             sizeof(struct list_head),
+                                             GFP_KERNEL);
        if (!nn->sessionid_hashtbl)
                goto err_sessionid;
 
index f8eb04387ca4372ee8acce8d28b29c89618477ae..fbd0090d7d0c4f3723f73fec9ed49f220337c635 100644 (file)
@@ -527,7 +527,7 @@ int ntfs_read_compressed_block(struct page *page)
        BUG_ON(ni->type != AT_DATA);
        BUG_ON(ni->name_len);
 
-       pages = kmalloc(nr_pages * sizeof(struct page *), GFP_NOFS);
+       pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_NOFS);
 
        /* Allocate memory to store the buffer heads we need. */
        bhs_size = cb_size / block_size * sizeof(struct buffer_head *);
index e5076185cc1ecf560193958a2bab37d106e340d7..1296f78ae9667ccdefe06fd7358502a0d9dda126 100644 (file)
@@ -1078,7 +1078,7 @@ int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *caller_vec,
        o2net_set_nst_sock_container(&nst, sc);
 
        veclen = caller_veclen + 1;
-       vec = kmalloc(sizeof(struct kvec) * veclen, GFP_ATOMIC);
+       vec = kmalloc_array(veclen, sizeof(struct kvec), GFP_ATOMIC);
        if (vec == NULL) {
                mlog(0, "failed to %zu element kvec!\n", veclen);
                ret = -ENOMEM;
index 425081be61610263962bcef9de4b9141252e5a57..2acd58ba9b7b27dbaf2a2834c8ee0aea7c609f94 100644 (file)
@@ -86,7 +86,7 @@ static void dlm_free_pagevec(void **vec, int pages)
 
 static void **dlm_alloc_pagevec(int pages)
 {
-       void **vec = kmalloc(pages * sizeof(void *), GFP_KERNEL);
+       void **vec = kmalloc_array(pages, sizeof(void *), GFP_KERNEL);
        int i;
 
        if (!vec)
index 4aa9ce5df02ffc9b6daf9d1d47157f5aee660799..80aa42506b8b7fa32902d8a61a04c28172c30995 100644 (file)
@@ -389,7 +389,8 @@ static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns,
        unsigned long *entries;
        int err;
 
-       entries = kmalloc(MAX_STACK_TRACE_DEPTH * sizeof(*entries), GFP_KERNEL);
+       entries = kmalloc_array(MAX_STACK_TRACE_DEPTH, sizeof(*entries),
+                               GFP_KERNEL);
        if (!entries)
                return -ENOMEM;
 
index 597969db9e903ef301a51d4db13d7372e12c7e14..e9679016271fba923290c24e13f5368f5f0e0199 100644 (file)
@@ -1473,7 +1473,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
        pm.show_pfn = file_ns_capable(file, &init_user_ns, CAP_SYS_ADMIN);
 
        pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT);
-       pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_KERNEL);
+       pm.buffer = kmalloc_array(pm.len, PM_ENTRY_BYTES, GFP_KERNEL);
        ret = -ENOMEM;
        if (!pm.buffer)
                goto out_mm;
index e83bd9744b5d3b9d81b0a95898a91ed0ec9ebce7..153f8f690490771208dbff66f458caaa9ec57d22 100644 (file)
@@ -778,7 +778,7 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
                goto out;
        }
        if (nr_segs > fast_segs) {
-               iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
+               iov = kmalloc_array(nr_segs, sizeof(struct iovec), GFP_KERNEL);
                if (iov == NULL) {
                        ret = -ENOMEM;
                        goto out;
@@ -849,7 +849,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
                goto out;
        if (nr_segs > fast_segs) {
                ret = -ENOMEM;
-               iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
+               iov = kmalloc_array(nr_segs, sizeof(struct iovec), GFP_KERNEL);
                if (iov == NULL)
                        goto out;
        }
index 23148c3ed67560fa97a10e5ef36e1024ad95aee7..358ee2a1ce1a55f3bb32d054013460fbb2277acf 100644 (file)
@@ -2192,10 +2192,12 @@ static int journal_read_transaction(struct super_block *sb,
         * now we know we've got a good transaction, and it was
         * inside the valid time ranges
         */
-       log_blocks = kmalloc(get_desc_trans_len(desc) *
-                            sizeof(struct buffer_head *), GFP_NOFS);
-       real_blocks = kmalloc(get_desc_trans_len(desc) *
-                             sizeof(struct buffer_head *), GFP_NOFS);
+       log_blocks = kmalloc_array(get_desc_trans_len(desc),
+                                  sizeof(struct buffer_head *),
+                                  GFP_NOFS);
+       real_blocks = kmalloc_array(get_desc_trans_len(desc),
+                                   sizeof(struct buffer_head *),
+                                   GFP_NOFS);
        if (!log_blocks || !real_blocks) {
                brelse(c_bh);
                brelse(d_bh);
index bc3cc0f9889611446ef94cda24ec5e20892c435f..317891ff8165ba19b775fcfaa8f6deccb58ba18f 100644 (file)
@@ -1236,7 +1236,7 @@ static int compat_core_sys_select(int n, compat_ulong_t __user *inp,
        size = FDS_BYTES(n);
        bits = stack_fds;
        if (size > sizeof(stack_fds) / 6) {
-               bits = kmalloc(6 * size, GFP_KERNEL);
+               bits = kmalloc_array(6, size, GFP_KERNEL);
                ret = -ENOMEM;
                if (!bits)
                        goto out_nofds;
index 005d09cf3fa879fd2fab8fd6a95433fefa7abc4d..2365ab073a2708982ba3eb74a008039aff67687f 100644 (file)
@@ -259,8 +259,9 @@ int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc
        if (buffers <= PIPE_DEF_BUFFERS)
                return 0;
 
-       spd->pages = kmalloc(buffers * sizeof(struct page *), GFP_KERNEL);
-       spd->partial = kmalloc(buffers * sizeof(struct partial_page), GFP_KERNEL);
+       spd->pages = kmalloc_array(buffers, sizeof(struct page *), GFP_KERNEL);
+       spd->partial = kmalloc_array(buffers, sizeof(struct partial_page),
+                                    GFP_KERNEL);
 
        if (spd->pages && spd->partial)
                return 0;
@@ -395,7 +396,7 @@ static ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
 
        vec = __vec;
        if (nr_pages > PIPE_DEF_BUFFERS) {
-               vec = kmalloc(nr_pages * sizeof(struct kvec), GFP_KERNEL);
+               vec = kmalloc_array(nr_pages, sizeof(struct kvec), GFP_KERNEL);
                if (unlikely(!vec)) {
                        res = -ENOMEM;
                        goto out;
index 9a517109da0feda2ac19ba4781072ab4ab4aad31..d4e45adddf1e19d06004df86a83c22ec95dcc251 100644 (file)
@@ -628,7 +628,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
        /* Needed by 'ubifs_pack_lsave()' */
        c->main_first = c->leb_cnt - *main_lebs;
 
-       lsave = kmalloc(sizeof(int) * c->lsave_cnt, GFP_KERNEL);
+       lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_KERNEL);
        pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
        nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
        buf = vmalloc(c->leb_size);
@@ -1636,15 +1636,17 @@ static int lpt_init_rd(struct ubifs_info *c)
                return -ENOMEM;
 
        for (i = 0; i < LPROPS_HEAP_CNT; i++) {
-               c->lpt_heap[i].arr = kmalloc(sizeof(void *) * LPT_HEAP_SZ,
-                                            GFP_KERNEL);
+               c->lpt_heap[i].arr = kmalloc_array(LPT_HEAP_SZ,
+                                                  sizeof(void *),
+                                                  GFP_KERNEL);
                if (!c->lpt_heap[i].arr)
                        return -ENOMEM;
                c->lpt_heap[i].cnt = 0;
                c->lpt_heap[i].max_cnt = LPT_HEAP_SZ;
        }
 
-       c->dirty_idx.arr = kmalloc(sizeof(void *) * LPT_HEAP_SZ, GFP_KERNEL);
+       c->dirty_idx.arr = kmalloc_array(LPT_HEAP_SZ, sizeof(void *),
+                                        GFP_KERNEL);
        if (!c->dirty_idx.arr)
                return -ENOMEM;
        c->dirty_idx.cnt = 0;
@@ -1697,7 +1699,7 @@ static int lpt_init_wr(struct ubifs_info *c)
                return -ENOMEM;
 
        if (c->big_lpt) {
-               c->lsave = kmalloc(sizeof(int) * c->lsave_cnt, GFP_NOFS);
+               c->lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_NOFS);
                if (!c->lsave)
                        return -ENOMEM;
                err = read_lsave(c);
@@ -1939,8 +1941,8 @@ int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
                        return err;
        }
 
-       path = kmalloc(sizeof(struct lpt_scan_node) * (c->lpt_hght + 1),
-                      GFP_NOFS);
+       path = kmalloc_array(c->lpt_hght + 1, sizeof(struct lpt_scan_node),
+                            GFP_NOFS);
        if (!path)
                return -ENOMEM;
 
index 6c397a389105a68f75b6c3dbaba9d7bf3e01c5af..c5466c70d620015aaa16ede0790aefb3c6efbc14 100644 (file)
@@ -1196,7 +1196,8 @@ static int mount_ubifs(struct ubifs_info *c)
         * never exceed 64.
         */
        err = -ENOMEM;
-       c->bottom_up_buf = kmalloc(BOTTOM_UP_HEIGHT * sizeof(int), GFP_KERNEL);
+       c->bottom_up_buf = kmalloc_array(BOTTOM_UP_HEIGHT, sizeof(int),
+                                        GFP_KERNEL);
        if (!c->bottom_up_buf)
                goto out_free;
 
index ba3d0e0f86151e533d98fb656910665a0da61e3c..4a21e7f75e7a16537353c90bf850e52709252a34 100644 (file)
@@ -1104,8 +1104,9 @@ static struct ubifs_znode *dirty_cow_bottom_up(struct ubifs_info *c,
        ubifs_assert(znode);
        if (c->zroot.znode->level > BOTTOM_UP_HEIGHT) {
                kfree(c->bottom_up_buf);
-               c->bottom_up_buf = kmalloc(c->zroot.znode->level * sizeof(int),
-                                          GFP_NOFS);
+               c->bottom_up_buf = kmalloc_array(c->zroot.znode->level,
+                                                sizeof(int),
+                                                GFP_NOFS);
                if (!c->bottom_up_buf)
                        return ERR_PTR(-ENOMEM);
                path = c->bottom_up_buf;
index aa31f60220ef4b8a52fa41d9261e1dffcb1dbc5e..a9df94ad46a34a91f95f4d25562760031937bb0a 100644 (file)
@@ -366,7 +366,8 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt)
 
        dbg_gc("%d znodes to write", cnt);
 
-       c->gap_lebs = kmalloc(sizeof(int) * (c->lst.idx_lebs + 1), GFP_NOFS);
+       c->gap_lebs = kmalloc_array(c->lst.idx_lebs + 1, sizeof(int),
+                                   GFP_NOFS);
        if (!c->gap_lebs)
                return -ENOMEM;
 
@@ -674,7 +675,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt)
        dbg_cmt("need about %d empty LEBS for TNC commit", leb_cnt);
        if (!leb_cnt)
                return 0;
-       c->ilebs = kmalloc(leb_cnt * sizeof(int), GFP_NOFS);
+       c->ilebs = kmalloc_array(leb_cnt, sizeof(int), GFP_NOFS);
        if (!c->ilebs)
                return -ENOMEM;
        for (i = 0; i < leb_cnt; i++) {
index 8254b8b3690fa7d553c4ec6187a99f9c420f023f..488088141451ba6c9dab80dd0c96a1502100b3f7 100644 (file)
@@ -541,7 +541,9 @@ static int ufs_read_cylinder_structures(struct super_block *sb)
         * Read cylinder group (we read only first fragment from block
         * at this time) and prepare internal data structures for cg caching.
         */
-       if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_NOFS)))
+       sbi->s_ucg = kmalloc_array(uspi->s_ncg, sizeof(struct buffer_head *),
+                                  GFP_NOFS);
+       if (!sbi->s_ucg)
                goto failed;
        for (i = 0; i < uspi->s_ncg; i++) 
                sbi->s_ucg[i] = NULL;
index b4b5b81e7251e6fab9530d9d0dd2f343d2045c0e..1603492c9cc7e7cfd98a677c43fad39c58cb85bb 100644 (file)
@@ -623,8 +623,9 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
        if (!key || key->prefixlen > trie->max_prefixlen)
                goto find_leftmost;
 
-       node_stack = kmalloc(trie->max_prefixlen * sizeof(struct lpm_trie_node *),
-                            GFP_ATOMIC | __GFP_NOWARN);
+       node_stack = kmalloc_array(trie->max_prefixlen,
+                                  sizeof(struct lpm_trie_node *),
+                                  GFP_ATOMIC | __GFP_NOWARN);
        if (!node_stack)
                return -ENOMEM;
 
index e06c97f3ed1a39c3e43a7895158b6a4a298d2bf3..9b3f9b04f8175d98ea3e24bd57625066310dd7df 100644 (file)
@@ -197,7 +197,7 @@ static void *pidlist_allocate(int count)
        if (PIDLIST_TOO_LARGE(count))
                return vmalloc(count * sizeof(pid_t));
        else
-               return kmalloc(count * sizeof(pid_t), GFP_KERNEL);
+               return kmalloc_array(count, sizeof(pid_t), GFP_KERNEL);
 }
 
 static void pidlist_free(void *p)
index b42037e6e81d3af0eb8a2d8c5cbdf4bbd56e5824..d8b12e0d39cd8e3b2f4733e1ce1dee2f2486ac12 100644 (file)
@@ -683,7 +683,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
                goto done;
        }
 
-       csa = kmalloc(nr_cpusets() * sizeof(cp), GFP_KERNEL);
+       csa = kmalloc_array(nr_cpusets(), sizeof(cp), GFP_KERNEL);
        if (!csa)
                goto done;
        csn = 0;
@@ -753,7 +753,8 @@ restart:
         * The rest of the code, including the scheduler, can deal with
         * dattr==NULL case. No need to abort if alloc fails.
         */
-       dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL);
+       dattr = kmalloc_array(ndoms, sizeof(struct sched_domain_attr),
+                             GFP_KERNEL);
 
        for (nslot = 0, i = 0; i < csn; i++) {
                struct cpuset *a = csa[i];
index e405677ee08d6ae6b71c36afd2270d2ed806810d..aaa69531fae2c2ab26d088332c5ff2966171c07f 100644 (file)
@@ -729,8 +729,8 @@ static int kdb_defcmd(int argc, const char **argv)
                kdb_printf("Command only available during kdb_init()\n");
                return KDB_NOTIMP;
        }
-       defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set),
-                            GFP_KDB);
+       defcmd_set = kmalloc_array(defcmd_set_count + 1, sizeof(*defcmd_set),
+                                  GFP_KDB);
        if (!defcmd_set)
                goto fail_defcmd;
        memcpy(defcmd_set, save_defcmd_set,
@@ -2706,8 +2706,11 @@ int kdb_register_flags(char *cmd,
        }
 
        if (i >= kdb_max_commands) {
-               kdbtab_t *new = kmalloc((kdb_max_commands - KDB_BASE_CMD_MAX +
-                        kdb_command_extend) * sizeof(*new), GFP_KDB);
+               kdbtab_t *new = kmalloc_array(kdb_max_commands -
+                                               KDB_BASE_CMD_MAX +
+                                               kdb_command_extend,
+                                             sizeof(*new),
+                                             GFP_KDB);
                if (!new) {
                        kdb_printf("Could not allocate new kdb_command "
                                   "table\n");
index 1d5632d8bbccfd941a6b0b1cf0ac380c4aeb0a5c..5349c91c22983c4b9dc0d362aacf9579a705cf70 100644 (file)
@@ -258,7 +258,7 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
        /* cut off if it is too long */
        if (count > KSYM_NAME_LEN)
                count = KSYM_NAME_LEN;
-       buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
+       buf = kmalloc(count + 1, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
index 6850ffd6912579ac6053a6bdcc22f3322acab261..4ceeb13a74ed70687ce7c1c06981710899a1bce4 100644 (file)
@@ -913,7 +913,9 @@ static int __init lock_torture_init(void)
        /* Initialize the statistics so that each run gets its own numbers. */
        if (nwriters_stress) {
                lock_is_write_held = 0;
-               cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
+               cxt.lwsa = kmalloc_array(cxt.nrealwriters_stress,
+                                        sizeof(*cxt.lwsa),
+                                        GFP_KERNEL);
                if (cxt.lwsa == NULL) {
                        VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory");
                        firsterr = -ENOMEM;
@@ -942,7 +944,9 @@ static int __init lock_torture_init(void)
 
                if (nreaders_stress) {
                        lock_is_read_held = 0;
-                       cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL);
+                       cxt.lrsa = kmalloc_array(cxt.nrealreaders_stress,
+                                                sizeof(*cxt.lrsa),
+                                                GFP_KERNEL);
                        if (cxt.lrsa == NULL) {
                                VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory");
                                firsterr = -ENOMEM;
index c955b10c973c0444ec491c7e6b3779b77fe1fa15..9f5326e8a036fd261de4e290ca7364a2eaaa8c22 100644 (file)
@@ -169,7 +169,8 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
        buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
        if (!buf)
                return NULL;
-       buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
+       buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *),
+                                    GFP_KERNEL);
        if (!buf->padding)
                goto free_buf;
 
index 61a1125c1ae4224e8f69938406f0d08ad47519b7..05a831427bc741e8d6290a6189bedbfda2457ded 100644 (file)
@@ -1750,7 +1750,7 @@ cpumask_var_t *alloc_sched_domains(unsigned int ndoms)
        int i;
        cpumask_var_t *doms;
 
-       doms = kmalloc(sizeof(*doms) * ndoms, GFP_KERNEL);
+       doms = kmalloc_array(ndoms, sizeof(*doms), GFP_KERNEL);
        if (!doms)
                return NULL;
        for (i = 0; i < ndoms; i++) {
index 8d83bcf9ef69fa894706b2005e5d5cf9fba97003..df4b6254f986fae4a016fb5922a3692d7affb4b9 100644 (file)
@@ -6830,9 +6830,10 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
        struct task_struct *g, *t;
 
        for (i = 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) {
-               ret_stack_list[i] = kmalloc(FTRACE_RETFUNC_DEPTH
-                                       * sizeof(struct ftrace_ret_stack),
-                                       GFP_KERNEL);
+               ret_stack_list[i] =
+                       kmalloc_array(FTRACE_RETFUNC_DEPTH,
+                                     sizeof(struct ftrace_ret_stack),
+                                     GFP_KERNEL);
                if (!ret_stack_list[i]) {
                        start = 0;
                        end = i;
@@ -6904,9 +6905,9 @@ static int start_graph_tracing(void)
        struct ftrace_ret_stack **ret_stack_list;
        int ret, cpu;
 
-       ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE *
-                               sizeof(struct ftrace_ret_stack *),
-                               GFP_KERNEL);
+       ret_stack_list = kmalloc_array(FTRACE_RETSTACK_ALLOC_SIZE,
+                                      sizeof(struct ftrace_ret_stack *),
+                                      GFP_KERNEL);
 
        if (!ret_stack_list)
                return -ENOMEM;
@@ -7088,9 +7089,10 @@ void ftrace_graph_init_idle_task(struct task_struct *t, int cpu)
 
                ret_stack = per_cpu(idle_ret_stack, cpu);
                if (!ret_stack) {
-                       ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH
-                                           * sizeof(struct ftrace_ret_stack),
-                                           GFP_KERNEL);
+                       ret_stack =
+                               kmalloc_array(FTRACE_RETFUNC_DEPTH,
+                                             sizeof(struct ftrace_ret_stack),
+                                             GFP_KERNEL);
                        if (!ret_stack)
                                return;
                        per_cpu(idle_ret_stack, cpu) = ret_stack;
@@ -7109,9 +7111,9 @@ void ftrace_graph_init_task(struct task_struct *t)
        if (ftrace_graph_active) {
                struct ftrace_ret_stack *ret_stack;
 
-               ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH
-                               * sizeof(struct ftrace_ret_stack),
-                               GFP_KERNEL);
+               ret_stack = kmalloc_array(FTRACE_RETFUNC_DEPTH,
+                                         sizeof(struct ftrace_ret_stack),
+                                         GFP_KERNEL);
                if (!ret_stack)
                        return;
                graph_init_task(t, ret_stack);
index 108ce3e1dc1374c21e8fc7fbc9756e095cb314fe..8ea8550156138e6edb800c8209cfe080151209d8 100644 (file)
@@ -1751,12 +1751,13 @@ static inline void set_cmdline(int idx, const char *cmdline)
 static int allocate_cmdlines_buffer(unsigned int val,
                                    struct saved_cmdlines_buffer *s)
 {
-       s->map_cmdline_to_pid = kmalloc(val * sizeof(*s->map_cmdline_to_pid),
-                                       GFP_KERNEL);
+       s->map_cmdline_to_pid = kmalloc_array(val,
+                                             sizeof(*s->map_cmdline_to_pid),
+                                             GFP_KERNEL);
        if (!s->map_cmdline_to_pid)
                return -ENOMEM;
 
-       s->saved_cmdlines = kmalloc(val * TASK_COMM_LEN, GFP_KERNEL);
+       s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL);
        if (!s->saved_cmdlines) {
                kfree(s->map_cmdline_to_pid);
                return -ENOMEM;
@@ -5063,7 +5064,7 @@ trace_insert_eval_map_file(struct module *mod, struct trace_eval_map **start,
         * where the head holds the module and length of array, and the
         * tail holds a pointer to the next list.
         */
-       map_array = kmalloc(sizeof(*map_array) * (len + 2), GFP_KERNEL);
+       map_array = kmalloc_array(len + 2, sizeof(*map_array), GFP_KERNEL);
        if (!map_array) {
                pr_warn("Unable to allocate trace eval mapping\n");
                return;
index 0171407d231f6219af55632fe32ef284c87e366c..e1c818dbc0d724c603be39463b83de8f021cf79f 100644 (file)
@@ -436,15 +436,15 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
 
        nr_preds += 2; /* For TRUE and FALSE */
 
-       op_stack = kmalloc(sizeof(*op_stack) * nr_parens, GFP_KERNEL);
+       op_stack = kmalloc_array(nr_parens, sizeof(*op_stack), GFP_KERNEL);
        if (!op_stack)
                return ERR_PTR(-ENOMEM);
-       prog_stack = kmalloc(sizeof(*prog_stack) * nr_preds, GFP_KERNEL);
+       prog_stack = kmalloc_array(nr_preds, sizeof(*prog_stack), GFP_KERNEL);
        if (!prog_stack) {
                parse_error(pe, -ENOMEM, 0);
                goto out_free;
        }
-       inverts = kmalloc(sizeof(*inverts) * nr_preds, GFP_KERNEL);
+       inverts = kmalloc_array(nr_preds, sizeof(*inverts), GFP_KERNEL);
        if (!inverts) {
                parse_error(pe, -ENOMEM, 0);
                goto out_free;
index 492c255e6c5a31ee135004123193310a8e6e3ce2..c3d7583fcd216d6f0b44b8d38c65ecc60c3e6fde 100644 (file)
@@ -764,8 +764,9 @@ static int insert_extent(struct uid_gid_map *map, struct uid_gid_extent *extent)
                struct uid_gid_extent *forward;
 
                /* Allocate memory for 340 mappings. */
-               forward = kmalloc(sizeof(struct uid_gid_extent) *
-                                UID_GID_MAP_MAX_EXTENTS, GFP_KERNEL);
+               forward = kmalloc_array(UID_GID_MAP_MAX_EXTENTS,
+                                       sizeof(struct uid_gid_extent),
+                                       GFP_KERNEL);
                if (!forward)
                        return -ENOMEM;
 
index 5c35752a9414ca004def7ad9c27f34f36bbe9029..1a19a0a93dc1cb8931c2f9f5d512650a5a1a0fe6 100644 (file)
@@ -69,7 +69,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp)
                return NULL;
 
        argc = count_argc(argv_str);
-       argv = kmalloc(sizeof(*argv) * (argc + 2), gfp);
+       argv = kmalloc_array(argc + 2, sizeof(*argv), gfp);
        if (!argv) {
                kfree(argv_str);
                return NULL;
index 835242e74aaa3372957e46291c08bdc16ec59882..75509a1511a3e0abaf78eeda2f0f6ae1cd86ea87 100644 (file)
@@ -64,11 +64,12 @@ static int interval_tree_test_init(void)
        unsigned long results;
        cycles_t time1, time2, time;
 
-       nodes = kmalloc(nnodes * sizeof(struct interval_tree_node), GFP_KERNEL);
+       nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node),
+                             GFP_KERNEL);
        if (!nodes)
                return -ENOMEM;
 
-       queries = kmalloc(nsearches * sizeof(int), GFP_KERNEL);
+       queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL);
        if (!queries) {
                kfree(nodes);
                return -ENOMEM;
index b0f757bf72136856aa6ae54d93692111bcc1b0c9..015656aa8182d081522615c3eb71d406cc7f809f 100644 (file)
@@ -54,7 +54,7 @@ int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,
                return -EINVAL;
        }
 
-       fifo->data = kmalloc(size * esize, gfp_mask);
+       fifo->data = kmalloc_array(esize, size, gfp_mask);
 
        if (!fifo->data) {
                fifo->mask = 0;
index 314f4dfa603ee98fd89e1f1006a09e8147af6cc7..2dbfc4c8a237b9836d070b6d3412ba1f4f25cf7b 100644 (file)
@@ -91,7 +91,7 @@ int mpi_resize(MPI a, unsigned nlimbs)
                return 0;       /* no need to do it */
 
        if (a->d) {
-               p = kmalloc(nlimbs * sizeof(mpi_limb_t), GFP_KERNEL);
+               p = kmalloc_array(nlimbs, sizeof(mpi_limb_t), GFP_KERNEL);
                if (!p)
                        return -ENOMEM;
                memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t));
index 7d36c1e27ff6550de3f921bd865029b2b56487f7..b7055b2a07d37ad577c2845cc2088108181764db 100644 (file)
@@ -247,7 +247,7 @@ static int __init rbtree_test_init(void)
        cycles_t time1, time2, time;
        struct rb_node *node;
 
-       nodes = kmalloc(nnodes * sizeof(*nodes), GFP_KERNEL);
+       nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL);
        if (!nodes)
                return -ENOMEM;
 
index dfcf54242fb92f50d544169b7c723b81e78f1984..d8bb1a1eba722f89fc307209ed97ba65f0579052 100644 (file)
@@ -88,15 +88,15 @@ static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int),
        rs->gffunc = gffunc;
 
        /* Allocate the arrays */
-       rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
+       rs->alpha_to = kmalloc_array(rs->nn + 1, sizeof(uint16_t), gfp);
        if (rs->alpha_to == NULL)
                goto err;
 
-       rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
+       rs->index_of = kmalloc_array(rs->nn + 1, sizeof(uint16_t), gfp);
        if (rs->index_of == NULL)
                goto err;
 
-       rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), gfp);
+       rs->genpoly = kmalloc_array(rs->nroots + 1, sizeof(uint16_t), gfp);
        if(rs->genpoly == NULL)
                goto err;
 
index 06dad7a072fd66385032f541f3c9f77b6d440235..1642fd507a960f5deb2b6d7366db83800a3e547b 100644 (file)
@@ -170,7 +170,8 @@ static struct scatterlist *sg_kmalloc(unsigned int nents, gfp_t gfp_mask)
                kmemleak_alloc(ptr, PAGE_SIZE, 1, gfp_mask);
                return ptr;
        } else
-               return kmalloc(nents * sizeof(struct scatterlist), gfp_mask);
+               return kmalloc_array(nents, sizeof(struct scatterlist),
+                                    gfp_mask);
 }
 
 static void sg_kfree(struct scatterlist *sg, unsigned int nents)
index ba8fdc0b6e7f712104e076244dc6def9ab2aa097..1cd7c1a57a144320b7d1729d7caa6ec93351cc54 100644 (file)
@@ -1131,8 +1131,8 @@ static int do_huge_pmd_wp_page_fallback(struct vm_fault *vmf, pmd_t orig_pmd,
        unsigned long mmun_start;       /* For mmu_notifiers */
        unsigned long mmun_end;         /* For mmu_notifiers */
 
-       pages = kmalloc(sizeof(struct page *) * HPAGE_PMD_NR,
-                       GFP_KERNEL);
+       pages = kmalloc_array(HPAGE_PMD_NR, sizeof(struct page *),
+                             GFP_KERNEL);
        if (unlikely(!pages)) {
                ret |= VM_FAULT_OOM;
                goto out;
index 696befffe6f7237b0d58f36839092e9f2a96aeec..3612fbb32e9d5412e8494e4c220fad84e3a4e779 100644 (file)
@@ -2798,7 +2798,8 @@ static int __init hugetlb_init(void)
        num_fault_mutexes = 1;
 #endif
        hugetlb_fault_mutex_table =
-               kmalloc(sizeof(struct mutex) * num_fault_mutexes, GFP_KERNEL);
+               kmalloc_array(num_fault_mutexes, sizeof(struct mutex),
+                             GFP_KERNEL);
        BUG_ON(!hugetlb_fault_mutex_table);
 
        for (i = 0; i < num_fault_mutexes; i++)
index 15505479c3abb8265d8e4a48ffc1aafbf5d185a1..faf5dcb7b44f1a53d4b3508450b5a948260c4740 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4412,8 +4412,9 @@ static long validate_slab_cache(struct kmem_cache *s)
 {
        int node;
        unsigned long count = 0;
-       unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
-                               sizeof(unsigned long), GFP_KERNEL);
+       unsigned long *map = kmalloc_array(BITS_TO_LONGS(oo_objects(s->max)),
+                                          sizeof(unsigned long),
+                                          GFP_KERNEL);
        struct kmem_cache_node *n;
 
        if (!map)
@@ -4573,8 +4574,9 @@ static int list_locations(struct kmem_cache *s, char *buf,
        unsigned long i;
        struct loc_track t = { 0, 0, NULL };
        int node;
-       unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
-                                    sizeof(unsigned long), GFP_KERNEL);
+       unsigned long *map = kmalloc_array(BITS_TO_LONGS(oo_objects(s->max)),
+                                          sizeof(unsigned long),
+                                          GFP_KERNEL);
        struct kmem_cache_node *n;
 
        if (!map || !alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location),
@@ -5293,7 +5295,7 @@ static int show_stat(struct kmem_cache *s, char *buf, enum stat_item si)
        unsigned long sum  = 0;
        int cpu;
        int len;
-       int *data = kmalloc(nr_cpu_ids * sizeof(int), GFP_KERNEL);
+       int *data = kmalloc_array(nr_cpu_ids, sizeof(int), GFP_KERNEL);
 
        if (!data)
                return -ENOMEM;
index 16e10680518c4cba784296ff96ddcc2643cabf82..931ea00c4fedb9a8a2c4d2ae9a1f24d7e51d7d04 100644 (file)
@@ -242,8 +242,9 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
                                                                "w", nwname);
                                if (!errcode) {
                                        *wnames =
-                                           kmalloc(sizeof(char *) * *nwname,
-                                                   GFP_NOFS);
+                                           kmalloc_array(*nwname,
+                                                         sizeof(char *),
+                                                         GFP_NOFS);
                                        if (!*wnames)
                                                errcode = -ENOMEM;
                                }
@@ -285,9 +286,9 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
                                    p9pdu_readf(pdu, proto_version, "w", nwqid);
                                if (!errcode) {
                                        *wqids =
-                                           kmalloc(*nwqid *
-                                                   sizeof(struct p9_qid),
-                                                   GFP_NOFS);
+                                           kmalloc_array(*nwqid,
+                                                         sizeof(struct p9_qid),
+                                                         GFP_NOFS);
                                        if (*wqids == NULL)
                                                errcode = -ENOMEM;
                                }
index 4d0372263e5d3057f0b300fbacb6f50a3c58e6ad..05006cbb33616e4a30de07180c1d400c91d05a10 100644 (file)
@@ -360,7 +360,8 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
                nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) -
                           (unsigned long)p / PAGE_SIZE;
 
-               *pages = kmalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
+               *pages = kmalloc_array(nr_pages, sizeof(struct page *),
+                                      GFP_NOFS);
                if (!*pages)
                        return -ENOMEM;
 
index 31e0dcb970f81c0bfb1a827c3a7203c14a4527db..75620c2f261723a915b74df013ac214479ba70c4 100644 (file)
@@ -472,7 +472,7 @@ static const uint8_t *copy_macs(struct mpoa_client *mpc,
                if (mpc->number_of_mps_macs != 0)
                        kfree(mpc->mps_macs);
                mpc->number_of_mps_macs = 0;
-               mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL);
+               mpc->mps_macs = kmalloc_array(ETH_ALEN, num_macs, GFP_KERNEL);
                if (mpc->mps_macs == NULL) {
                        pr_info("(%s) out of mem\n", mpc->dev->name);
                        return NULL;
index 1dec337901988ad96b6eeaf6b7a46f3da85f59c7..ee8ef12282639d09ac975c7ef0e09b644a719009 100644 (file)
@@ -1281,7 +1281,7 @@ int hci_inquiry(void __user *arg)
        /* cache_dump can't sleep. Therefore we allocate temp buffer and then
         * copy it to the user space.
         */
-       buf = kmalloc(sizeof(struct inquiry_info) * max_rsp, GFP_KERNEL);
+       buf = kmalloc_array(max_rsp, sizeof(struct inquiry_info), GFP_KERNEL);
        if (!buf) {
                err = -ENOMEM;
                goto done;
index 9b7907ebfa01b0332be1528b507465c1a304ebe6..d17a4736e47c0abf6fe3be7df34f60bd1f32f1fb 100644 (file)
@@ -331,7 +331,7 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size)
         */
        alloc_size = roundup_pow_of_two(size);
 
-       seq_list->list = kmalloc(sizeof(u16) * alloc_size, GFP_KERNEL);
+       seq_list->list = kmalloc_array(alloc_size, sizeof(u16), GFP_KERNEL);
        if (!seq_list->list)
                return -ENOMEM;
 
index 97fedff3f0c4f56bea5f04d1708c59608ab87982..394ff1d2791f1e3947a4ed0c8953f9d9b227b35a 100644 (file)
@@ -923,8 +923,9 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 
                /* create array for CAN frames and copy the data */
                if (msg_head->nframes > 1) {
-                       op->frames = kmalloc(msg_head->nframes * op->cfsiz,
-                                            GFP_KERNEL);
+                       op->frames = kmalloc_array(msg_head->nframes,
+                                                  op->cfsiz,
+                                                  GFP_KERNEL);
                        if (!op->frames) {
                                kfree(op);
                                return -ENOMEM;
@@ -1095,8 +1096,9 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 
                if (msg_head->nframes > 1) {
                        /* create array for CAN frames and copy the data */
-                       op->frames = kmalloc(msg_head->nframes * op->cfsiz,
-                                            GFP_KERNEL);
+                       op->frames = kmalloc_array(msg_head->nframes,
+                                                  op->cfsiz,
+                                                  GFP_KERNEL);
                        if (!op->frames) {
                                kfree(op);
                                return -ENOMEM;
index 9645ffd6acfb24b1432ad69f655d1caa09741fcf..e22820e24f501224c2ebdc8f0dcc0cc0b59ae66d 100644 (file)
@@ -1299,8 +1299,9 @@ static int set_primary_affinity(struct ceph_osdmap *map, int osd, u32 aff)
        if (!map->osd_primary_affinity) {
                int i;
 
-               map->osd_primary_affinity = kmalloc(map->max_osd*sizeof(u32),
-                                                   GFP_NOFS);
+               map->osd_primary_affinity = kmalloc_array(map->max_osd,
+                                                         sizeof(u32),
+                                                         GFP_NOFS);
                if (!map->osd_primary_affinity)
                        return -ENOMEM;
 
index a3d0adc828e6417e7772420fddbdff1313064f65..e560d3975f41cb89827017b1e920e43648d5b453 100644 (file)
@@ -20,7 +20,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
        int got = 0;
        int rc = 0;
 
-       pages = kmalloc(sizeof(*pages) * num_pages, GFP_NOFS);
+       pages = kmalloc_array(num_pages, sizeof(*pages), GFP_NOFS);
        if (!pages)
                return ERR_PTR(-ENOMEM);
 
@@ -74,7 +74,7 @@ struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags)
        struct page **pages;
        int i;
 
-       pages = kmalloc(sizeof(*pages) * num_pages, flags);
+       pages = kmalloc_array(num_pages, sizeof(*pages), flags);
        if (!pages)
                return ERR_PTR(-ENOMEM);
        for (i = 0; i < num_pages; i++) {
index 6e18242a1caec5b4e2504f75622691dfaf1039c1..57b7bab5f70bb7c50a8be565cc90a40bc1c2d5d6 100644 (file)
@@ -8823,7 +8823,7 @@ static struct hlist_head * __net_init netdev_create_hash(void)
        int i;
        struct hlist_head *hash;
 
-       hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL);
+       hash = kmalloc_array(NETDEV_HASHENTRIES, sizeof(*hash), GFP_KERNEL);
        if (hash != NULL)
                for (i = 0; i < NETDEV_HASHENTRIES; i++)
                        INIT_HLIST_HEAD(&hash[i]);
index c15075dc7572cdd993e17e7ccc765c22c23bc75a..436e4f9cc7f01d014930b4b0d1959a93aadd6c1a 100644 (file)
@@ -1816,7 +1816,7 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
                return -EFAULT;
 
        test.len = test_len;
-       data = kmalloc(test_len * sizeof(u64), GFP_USER);
+       data = kmalloc_array(test_len, sizeof(u64), GFP_USER);
        if (!data)
                return -ENOMEM;
 
index d2f4e0c1faafa985f67bda48b55ea1bf409be05f..2589a6b78aa175a207cf592e5c8b611ca95f232e 100644 (file)
@@ -984,7 +984,8 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
         */
        err = ops->peer_getappinfo(netdev, &info, &app_count);
        if (!err && app_count) {
-               table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
+               table = kmalloc_array(app_count, sizeof(struct dcb_app),
+                                     GFP_KERNEL);
                if (!table)
                        return -ENOMEM;
 
index 385f153fe0318a160120e98a093260a55e485317..2b75df469220a8a5bf3ffa09aa6616eef0a9002d 100644 (file)
@@ -46,7 +46,8 @@ static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
                return -ENOMEM;
 
        /* allocate buffer and initialize linked list */
-       seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any());
+       seqp = kmalloc_array(CCID2_SEQBUF_LEN, sizeof(struct ccid2_seq),
+                            gfp_any());
        if (seqp == NULL)
                return -ENOMEM;
 
index bf4e4adc2d0002c3acc016bfa7e128a477150b33..6bcd1eacc1f0fc53315d26ea27bfcd14563cc9a1 100644 (file)
@@ -3146,7 +3146,8 @@ int __init ip_rt_init(void)
 {
        int cpu;
 
-       ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
+       ip_idents = kmalloc_array(IP_IDENTS_SZ, sizeof(*ip_idents),
+                                 GFP_KERNEL);
        if (!ip_idents)
                panic("IP: failed to allocate ip_idents\n");
 
index 4d2e797e3f168bdf784268b16de15799220e0146..fb1b1f9e7e5e03281fabe79175c62f3817354d0d 100644 (file)
@@ -772,7 +772,7 @@ static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
                if (have_mfp)
                        n_suites += 4;
 
-               suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
+               suites = kmalloc_array(n_suites, sizeof(u32), GFP_KERNEL);
                if (!suites)
                        return -ENOMEM;
 
index 8221bc5582abf74251a6c76550e1a8dce71538e3..7fadfbca9f1b09d2c658e3cfe761aea3aa70e7e5 100644 (file)
@@ -596,7 +596,7 @@ minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
        if (!mi->r)
                goto error;
 
-       mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
+       mi->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
        if (!mi->sample_table)
                goto error1;
 
index fb586b6e5d49ddd0617bbcbe9464038bc0b20d2e..267ab9d5137e9733057aa8227926f851715e570d 100644 (file)
@@ -1317,7 +1317,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
        if (!msp->ratelist)
                goto error;
 
-       msp->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
+       msp->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
        if (!msp->sample_table)
                goto error1;
 
index afdeca53e88b3fcbfe4c5815ee1b24945c6a61d8..d88841fbc560fcac4194938f4354907e51ecbcbf 100644 (file)
@@ -402,7 +402,8 @@ int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *l4proto)
                struct nf_conntrack_l4proto __rcu **proto_array;
                int i;
 
-               proto_array = kmalloc(MAX_NF_CT_PROTO *
+               proto_array =
+                       kmalloc_array(MAX_NF_CT_PROTO,
                                      sizeof(struct nf_conntrack_l4proto *),
                                      GFP_KERNEL);
                if (proto_array == NULL) {
index b7df32a56e7ed2b495e39b54a7219a59af1531e4..46f9df99d276c3be7ff5839ba41273df38e59a72 100644 (file)
@@ -691,8 +691,9 @@ int nf_nat_l4proto_register(u8 l3proto, const struct nf_nat_l4proto *l4proto)
 
        mutex_lock(&nf_nat_proto_mutex);
        if (nf_nat_l4protos[l3proto] == NULL) {
-               l4protos = kmalloc(IPPROTO_MAX * sizeof(struct nf_nat_l4proto *),
-                                  GFP_KERNEL);
+               l4protos = kmalloc_array(IPPROTO_MAX,
+                                        sizeof(struct nf_nat_l4proto *),
+                                        GFP_KERNEL);
                if (l4protos == NULL) {
                        ret = -ENOMEM;
                        goto out;
index ca4c4d994ddb09540b41fb28650552b31f85b4d9..cae4a026859dc65a3042ca90007a778c81bf5fdd 100644 (file)
@@ -7164,8 +7164,8 @@ static int __init nf_tables_module_init(void)
 
        nft_chain_filter_init();
 
-       info = kmalloc(sizeof(struct nft_expr_info) * NFT_RULE_MAXEXPRS,
-                      GFP_KERNEL);
+       info = kmalloc_array(NFT_RULE_MAXEXPRS, sizeof(struct nft_expr_info),
+                            GFP_KERNEL);
        if (info == NULL) {
                err = -ENOMEM;
                goto err1;
index df9ab71b0ed95a73e0e16443087507b91709c80d..d0d8397c95889f5b947def5ba90b62ac6b1bcaa7 100644 (file)
@@ -1904,7 +1904,7 @@ static int __init xt_init(void)
                seqcount_init(&per_cpu(xt_recseq, i));
        }
 
-       xt = kmalloc(sizeof(struct xt_af) * NFPROTO_NUMPROTO, GFP_KERNEL);
+       xt = kmalloc_array(NFPROTO_NUMPROTO, sizeof(struct xt_af), GFP_KERNEL);
        if (!xt)
                return -ENOMEM;
 
index b9ce82c9440f1cde865a456ca926a6f5782c29a7..25eeb6d2a75a69059f387be103345e844284f743 100644 (file)
@@ -352,8 +352,9 @@ int genl_register_family(struct genl_family *family)
        }
 
        if (family->maxattr && !family->parallel_ops) {
-               family->attrbuf = kmalloc((family->maxattr+1) *
-                                       sizeof(struct nlattr *), GFP_KERNEL);
+               family->attrbuf = kmalloc_array(family->maxattr + 1,
+                                               sizeof(struct nlattr *),
+                                               GFP_KERNEL);
                if (family->attrbuf == NULL) {
                        err = -ENOMEM;
                        goto errout_locked;
@@ -566,8 +567,9 @@ static int genl_family_rcv_msg(const struct genl_family *family,
                return -EOPNOTSUPP;
 
        if (family->maxattr && family->parallel_ops) {
-               attrbuf = kmalloc((family->maxattr+1) *
-                                       sizeof(struct nlattr *), GFP_KERNEL);
+               attrbuf = kmalloc_array(family->maxattr + 1,
+                                       sizeof(struct nlattr *),
+                                       GFP_KERNEL);
                if (attrbuf == NULL)
                        return -ENOMEM;
        } else
index a61818e943969936ba4cc2c49818b7b889d5faf5..0f5ce77460d44099277e142e37d11620e426e9cb 100644 (file)
@@ -1578,8 +1578,9 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
                goto err_destroy_table;
        }
 
-       dp->ports = kmalloc(DP_VPORT_HASH_BUCKETS * sizeof(struct hlist_head),
-                           GFP_KERNEL);
+       dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
+                                 sizeof(struct hlist_head),
+                                 GFP_KERNEL);
        if (!dp->ports) {
                err = -ENOMEM;
                goto err_destroy_percpu;
index 140a44a5f7b7f1c08b3f329707b72fc75a9a81fe..e367a97a18c805f7e0c6c473e5e273d280acc2fb 100644 (file)
@@ -188,7 +188,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
        nr_pages = (PAGE_ALIGN(start + len) - (start & PAGE_MASK))
                        >> PAGE_SHIFT;
 
-       pages = kmalloc(nr_pages * sizeof(struct page *), GFP_KERNEL);
+       pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
        if (!pages) {
                ret = -ENOMEM;
                goto out;
index 6c0ae27fff84e2312bdc6a7f84abc7ed288e05de..278ac0807a60a8664bbb825ccd06737a595d8631 100644 (file)
@@ -432,7 +432,7 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb,
 
        sg = _sg;
        if (unlikely(nsg > 4)) {
-               sg = kmalloc(sizeof(*sg) * nsg, GFP_NOIO);
+               sg = kmalloc_array(nsg, sizeof(*sg), GFP_NOIO);
                if (!sg)
                        goto nomem;
        }
index 11d93377ba5e86b6863b7a16b95e2f599d01f8c1..5dffbc4930086699cefa10f704de5fd2068169c8 100644 (file)
@@ -1438,7 +1438,7 @@ static __init int sctp_init(void)
        /* Allocate and initialize the endpoint hash table.  */
        sctp_ep_hashsize = 64;
        sctp_ep_hashtable =
-               kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL);
+               kmalloc_array(64, sizeof(struct sctp_hashbucket), GFP_KERNEL);
        if (!sctp_ep_hashtable) {
                pr_err("Failed endpoint_hash alloc\n");
                status = -ENOMEM;
index 9463af4b32e8d7d688523986c584e73046d4dd7a..be8f103d22fdb7e439bb3ae610aaa3726a4b8332 100644 (file)
@@ -1753,7 +1753,8 @@ alloc_enc_pages(struct rpc_rqst *rqstp)
        last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_SHIFT;
        rqstp->rq_enc_pages_num = last - first + 1 + 1;
        rqstp->rq_enc_pages
-               = kmalloc(rqstp->rq_enc_pages_num * sizeof(struct page *),
+               = kmalloc_array(rqstp->rq_enc_pages_num,
+                               sizeof(struct page *),
                                GFP_NOFS);
        if (!rqstp->rq_enc_pages)
                goto out;
index 4492cda45566503627ad20a648524fdd59e3cbde..a2f76743c73af07bdfe3ed524aebb6d5bb000dbc 100644 (file)
@@ -285,8 +285,9 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
        if (!trans_buf)
                return -ENOMEM;
 
-       attrbuf = kmalloc((tipc_genl_family.maxattr + 1) *
-                       sizeof(struct nlattr *), GFP_KERNEL);
+       attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1,
+                               sizeof(struct nlattr *),
+                               GFP_KERNEL);
        if (!attrbuf) {
                err = -ENOMEM;
                goto trans_out;
index 42377668202597527bf5ac660342031ecf4afdd5..b69d3b1777c25d1d3f9cc5af3514352ed0220fcc 100644 (file)
@@ -1148,7 +1148,7 @@ static long trusted_read(const struct key *key, char __user *buffer,
                return -EINVAL;
 
        if (buffer && buflen >= 2 * p->blob_len) {
-               ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
+               ascii_buf = kmalloc_array(2, p->blob_len, GFP_KERNEL);
                if (!ascii_buf)
                        return -ENOMEM;
 
index 39d853bfa5ac0a8b88eb802ea12b947c35557a09..946ab080ac00315f6dc818bd4842970820b71029 100644 (file)
@@ -426,7 +426,7 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
            get_user(frames, &data32->frames))
                return -EFAULT;
        bufptr = compat_ptr(buf);
-       bufs = kmalloc(sizeof(void __user *) * ch, GFP_KERNEL);
+       bufs = kmalloc_array(ch, sizeof(void __user *), GFP_KERNEL);
        if (bufs == NULL)
                return -ENOMEM;
        for (i = 0; i < ch; i++) {
index 04c6301394d053ce5751ae33087c080cddd59b71..cecc79772c947ecde8237e199b6043eb39e38e44 100644 (file)
@@ -3072,7 +3072,7 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to)
        if (!frame_aligned(runtime, to->iov->iov_len))
                return -EINVAL;
        frames = bytes_to_samples(runtime, to->iov->iov_len);
-       bufs = kmalloc(sizeof(void *) * to->nr_segs, GFP_KERNEL);
+       bufs = kmalloc_array(to->nr_segs, sizeof(void *), GFP_KERNEL);
        if (bufs == NULL)
                return -ENOMEM;
        for (i = 0; i < to->nr_segs; ++i)
@@ -3107,7 +3107,7 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from)
            !frame_aligned(runtime, from->iov->iov_len))
                return -EINVAL;
        frames = bytes_to_samples(runtime, from->iov->iov_len);
-       bufs = kmalloc(sizeof(void *) * from->nr_segs, GFP_KERNEL);
+       bufs = kmalloc_array(from->nr_segs, sizeof(void *), GFP_KERNEL);
        if (bufs == NULL)
                return -ENOMEM;
        for (i = 0; i < from->nr_segs; ++i)
index 9e2912e3e80fd6822324198def600b60f3e7d709..288f839a554b5afbfbb7421d8bc464e6c045d86c 100644 (file)
@@ -657,7 +657,7 @@ static struct snd_midi_channel *snd_midi_channel_init_set(int n)
        struct snd_midi_channel *chan;
        int  i;
 
-       chan = kmalloc(n * sizeof(struct snd_midi_channel), GFP_KERNEL);
+       chan = kmalloc_array(n, sizeof(struct snd_midi_channel), GFP_KERNEL);
        if (chan) {
                for (i = 0; i < n; i++)
                        snd_midi_channel_init(chan+i, i);
index ea1506679c6650753b2efea810e77d85c9ddb0f5..1ebf00c83409666579b2a35d9b05836dd2f745bf 100644 (file)
@@ -27,7 +27,7 @@ int iso_packets_buffer_init(struct iso_packets_buffer *b, struct fw_unit *unit,
        void *p;
        int err;
 
-       b->packets = kmalloc(count * sizeof(*b->packets), GFP_KERNEL);
+       b->packets = kmalloc_array(count, sizeof(*b->packets), GFP_KERNEL);
        if (!b->packets) {
                err = -ENOMEM;
                goto error;
index 8c0f8a9ee0baef5bd42961742b91b50356f90bbb..fc9bcd47d6a4c8ae92dfb620041411d887e32b6f 100644 (file)
@@ -420,7 +420,7 @@ static int sq_allocate_buffers(struct sound_queue *sq, int num, int size)
                return 0;
        sq->numBufs = num;
        sq->bufSize = size;
-       sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL);
+       sq->buffers = kmalloc_array (num, sizeof(char *), GFP_KERNEL);
        if (!sq->buffers)
                return -ENOMEM;
        for (i = 0; i < num; i++) {
index ed1251c5f449a9f2189745e03d6bfcc5e7eb61ba..146e1a3498c7352c53751871fb1dfd166df8dac1 100644 (file)
@@ -460,7 +460,7 @@ static int load_firmware(struct snd_cs46xx *chip,
                entry->size = le32_to_cpu(fwdat[fwlen++]);
                if (fwlen + entry->size > fwsize)
                        goto error_inval;
-               entry->data = kmalloc(entry->size * 4, GFP_KERNEL);
+               entry->data = kmalloc_array(entry->size, 4, GFP_KERNEL);
                if (!entry->data)
                        goto error;
                memcpy_le32(entry->data, &fwdat[fwlen], entry->size * 4);
@@ -4036,8 +4036,9 @@ int snd_cs46xx_create(struct snd_card *card,
        snd_cs46xx_proc_init(card, chip);
 
 #ifdef CONFIG_PM_SLEEP
-       chip->saved_regs = kmalloc(sizeof(*chip->saved_regs) *
-                                  ARRAY_SIZE(saved_regs), GFP_KERNEL);
+       chip->saved_regs = kmalloc_array(ARRAY_SIZE(saved_regs),
+                                        sizeof(*chip->saved_regs),
+                                        GFP_KERNEL);
        if (!chip->saved_regs) {
                snd_cs46xx_free(chip);
                return -ENOMEM;
index c44eadef64ae20db5d31e0d00ed416b629fe4289..99d5a02f91692774c80685e1d6b89a7d83a7c724 100644 (file)
@@ -243,7 +243,9 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
        ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) *
                                            DSP_MAX_SYMBOLS);
        ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
-       ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
+       ins->modules = kmalloc_array(DSP_MAX_MODULES,
+                                    sizeof(struct dsp_module_desc),
+                                    GFP_KERNEL);
        if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
                cs46xx_dsp_spos_destroy(chip);
                goto error;
index b45a01bb73e5cd4f6f69c33f1dc367b6beb01000..af1085d946ec63378456313de2dc2de5550a8400 100644 (file)
@@ -2683,12 +2683,12 @@ int snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
        int len;
 
        len = emu->audigy ? 0x200 : 0x100;
-       emu->saved_gpr = kmalloc(len * 4, GFP_KERNEL);
+       emu->saved_gpr = kmalloc_array(len, 4, GFP_KERNEL);
        if (! emu->saved_gpr)
                return -ENOMEM;
        len = emu->audigy ? 0x100 : 0xa0;
-       emu->tram_val_saved = kmalloc(len * 4, GFP_KERNEL);
-       emu->tram_addr_saved = kmalloc(len * 4, GFP_KERNEL);
+       emu->tram_val_saved = kmalloc_array(len, 4, GFP_KERNEL);
+       emu->tram_addr_saved = kmalloc_array(len, 4, GFP_KERNEL);
        if (! emu->tram_val_saved || ! emu->tram_addr_saved)
                return -ENOMEM;
        len = emu->audigy ? 2 * 1024 : 2 * 512;
index 08151f3c0b139703fcd175cc5c255f66f89755ca..d91c87e41756ea5fceaee73d84e211b9ebba929d 100644 (file)
@@ -158,7 +158,7 @@ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
        len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
        if (len == -ENOSPC) {
                len = snd_hda_get_num_raw_conns(codec, nid);
-               result = kmalloc(sizeof(hda_nid_t) * len, GFP_KERNEL);
+               result = kmalloc_array(len, sizeof(hda_nid_t), GFP_KERNEL);
                if (!result)
                        return -ENOMEM;
                len = snd_hda_get_raw_connections(codec, nid, result, len);
@@ -438,7 +438,7 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
        int i;
        hda_nid_t nid;
 
-       codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL);
+       codec->wcaps = kmalloc_array(codec->core.num_nodes, 4, GFP_KERNEL);
        if (!codec->wcaps)
                return -ENOMEM;
        nid = codec->core.start_nid;
index 033aa84365b9b26de27dbb2918498c1d114b892b..c6b778b2580c12c7f34a08147ce623099f386cff 100644 (file)
@@ -825,8 +825,9 @@ static void print_codec_info(struct snd_info_entry *entry,
                if (wid_caps & AC_WCAP_CONN_LIST) {
                        conn_len = snd_hda_get_num_raw_conns(codec, nid);
                        if (conn_len > 0) {
-                               conn = kmalloc(sizeof(hda_nid_t) * conn_len,
-                                              GFP_KERNEL);
+                               conn = kmalloc_array(conn_len,
+                                                    sizeof(hda_nid_t),
+                                                    GFP_KERNEL);
                                if (!conn)
                                        return;
                                if (snd_hda_get_raw_connections(codec, nid, conn,
index 3a1c0b8b4ea276e840ce9f397cecc61610e736f6..c488c5afa19591410d4c872bd3decf531f0c4555 100644 (file)
@@ -439,7 +439,9 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
                        return -ENOMEM;
        }
        if (! dev->idx_table) {
-               dev->idx_table = kmalloc(sizeof(*dev->idx_table) * VIA_TABLE_SIZE, GFP_KERNEL);
+               dev->idx_table = kmalloc_array(VIA_TABLE_SIZE,
+                                              sizeof(*dev->idx_table),
+                                              GFP_KERNEL);
                if (! dev->idx_table)
                        return -ENOMEM;
        }
index 8a69221c1b86db0410fa64a981bafd37e7a69c79..b13c8688cc8d98b947910a6a86653fc5b8b0d1ab 100644 (file)
@@ -292,7 +292,9 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
                        return -ENOMEM;
        }
        if (! dev->idx_table) {
-               dev->idx_table = kmalloc(sizeof(*dev->idx_table) * VIA_TABLE_SIZE, GFP_KERNEL);
+               dev->idx_table = kmalloc_array(VIA_TABLE_SIZE,
+                                              sizeof(*dev->idx_table),
+                                              GFP_KERNEL);
                if (! dev->idx_table)
                        return -ENOMEM;
        }
index 8ca2e41e58270044c1442eb8b5546688cd519c83..6f81396aadc9efc510c4b3dc7bf49f3895e62936 100644 (file)
@@ -2435,8 +2435,8 @@ int snd_ymfpci_create(struct snd_card *card,
                goto free_chip;
 
 #ifdef CONFIG_PM_SLEEP
-       chip->saved_regs = kmalloc(YDSXGR_NUM_SAVED_REGS * sizeof(u32),
-                                  GFP_KERNEL);
+       chip->saved_regs = kmalloc_array(YDSXGR_NUM_SAVED_REGS, sizeof(u32),
+                                        GFP_KERNEL);
        if (chip->saved_regs == NULL) {
                err = -ENOMEM;
                goto free_chip;
index f13ef334c0d728dec446c24b7da63d0fa1d4fdc3..9037a35b931dbc7a6c07173439d456f81b3bba76 100644 (file)
@@ -2023,8 +2023,9 @@ static void wm8904_handle_pdata(struct snd_soc_component *component)
                                     wm8904_get_drc_enum, wm8904_put_drc_enum);
 
                /* We need an array of texts for the enum API */
-               wm8904->drc_texts = kmalloc(sizeof(char *)
-                                           * pdata->num_drc_cfgs, GFP_KERNEL);
+               wm8904->drc_texts = kmalloc_array(pdata->num_drc_cfgs,
+                                                 sizeof(char *),
+                                                 GFP_KERNEL);
                if (!wm8904->drc_texts)
                        return;
 
index 8d495220fa25d840b1090294b297b6e737339c26..108e8bf42a346e3651076b9b320e973787046eb2 100644 (file)
@@ -932,8 +932,9 @@ void wm8958_dsp2_init(struct snd_soc_component *component)
                };
 
                /* We need an array of texts for the enum API */
-               wm8994->mbc_texts = kmalloc(sizeof(char *)
-                                           * pdata->num_mbc_cfgs, GFP_KERNEL);
+               wm8994->mbc_texts = kmalloc_array(pdata->num_mbc_cfgs,
+                                                 sizeof(char *),
+                                                 GFP_KERNEL);
                if (!wm8994->mbc_texts)
                        return;
 
@@ -957,8 +958,9 @@ void wm8958_dsp2_init(struct snd_soc_component *component)
                };
 
                /* We need an array of texts for the enum API */
-               wm8994->vss_texts = kmalloc(sizeof(char *)
-                                           * pdata->num_vss_cfgs, GFP_KERNEL);
+               wm8994->vss_texts = kmalloc_array(pdata->num_vss_cfgs,
+                                                 sizeof(char *),
+                                                 GFP_KERNEL);
                if (!wm8994->vss_texts)
                        return;
 
@@ -983,8 +985,9 @@ void wm8958_dsp2_init(struct snd_soc_component *component)
                };
 
                /* We need an array of texts for the enum API */
-               wm8994->vss_hpf_texts = kmalloc(sizeof(char *)
-                                               * pdata->num_vss_hpf_cfgs, GFP_KERNEL);
+               wm8994->vss_hpf_texts = kmalloc_array(pdata->num_vss_hpf_cfgs,
+                                                     sizeof(char *),
+                                                     GFP_KERNEL);
                if (!wm8994->vss_hpf_texts)
                        return;
 
@@ -1010,8 +1013,9 @@ void wm8958_dsp2_init(struct snd_soc_component *component)
                };
 
                /* We need an array of texts for the enum API */
-               wm8994->enh_eq_texts = kmalloc(sizeof(char *)
-                                               * pdata->num_enh_eq_cfgs, GFP_KERNEL);
+               wm8994->enh_eq_texts = kmalloc_array(pdata->num_enh_eq_cfgs,
+                                                    sizeof(char *),
+                                                    GFP_KERNEL);
                if (!wm8994->enh_eq_texts)
                        return;
 
index fb1c1eac0b5ef3b56cd9b9873d46f694eda43457..f35d29f49ffe13afae1501c219d500e8f3212383 100644 (file)
@@ -728,7 +728,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
                usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) :
                usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE);
 
-       urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL);
+       urbs = kmalloc_array(N_URBS, sizeof(*urbs), GFP_KERNEL);
        if (!urbs) {
                *ret = -ENOMEM;
                return NULL;
@@ -742,7 +742,8 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
                }
 
                urbs[i]->transfer_buffer =
-                       kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL);
+                       kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB,
+                                     GFP_KERNEL);
                if (!urbs[i]->transfer_buffer) {
                        *ret = -ENOMEM;
                        return urbs;
@@ -857,7 +858,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
                                &snd_usb_caiaq_ops);
 
        cdev->data_cb_info =
-               kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS,
+               kmalloc_array(N_URBS, sizeof(struct snd_usb_caiaq_cb_info),
                                        GFP_KERNEL);
 
        if (!cdev->data_cb_info)
index 49e7ec6d2399072c456f5f7975a5a2a22a5bf94a..1f7a74a77ea34f6c7f86dc5259e716d5bd09e8f7 100644 (file)
@@ -188,7 +188,8 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
                 */
                int r, idx;
 
-               fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
+               fp->rate_table = kmalloc_array(nr_rates, sizeof(int),
+                                              GFP_KERNEL);
                if (fp->rate_table == NULL)
                        return -ENOMEM;
 
@@ -362,7 +363,7 @@ static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip,
                goto err_free;
        }
 
-       fp->rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
+       fp->rate_table = kmalloc_array(fp->nr_rates, sizeof(int), GFP_KERNEL);
        if (!fp->rate_table) {
                ret = -ENOMEM;
                goto err_free;
index b3854f8c0c679f4d5da9b3ab00a644eacb5c99d9..72c6f8e82a7e9cb06e9c4489064d05dc39891448 100644 (file)
@@ -158,8 +158,10 @@ static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm,
 
        /* Invoked multiple times in a row so allocate once only */
        if (!test_and_set_bit(type, &pstr->opened) && !pstr->buffer) {
-               pstr->buffer = kmalloc(line6pcm->line6->iso_buffers *
-                                      LINE6_ISO_PACKETS * pkt_size, GFP_KERNEL);
+               pstr->buffer =
+                       kmalloc(array3_size(line6pcm->line6->iso_buffers,
+                                           LINE6_ISO_PACKETS, pkt_size),
+                               GFP_KERNEL);
                if (!pstr->buffer)
                        return -ENOMEM;
        }
index 898afd3001ea0bb64f4fa9237df32c41bc68b2c2..8c3568d8d03bab132e5399fccd7cba184c81ed2a 100644 (file)
@@ -2515,7 +2515,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
                cval->control = (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR) ?
                        UAC2_CX_CLOCK_SELECTOR : UAC2_SU_SELECTOR;
 
-       namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL);
+       namelist = kmalloc_array(desc->bNrInPins, sizeof(char *), GFP_KERNEL);
        if (!namelist) {
                kfree(cval);
                return -ENOMEM;
index 78d1cad08a0ae6fcef52cae202653c7250f1ace4..160f52c4871b6a20a32625dabdef3a0032b3a210 100644 (file)
@@ -1123,7 +1123,7 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
                return 0;
 
        subs->rate_list.list = rate_list =
-               kmalloc(sizeof(int) * count, GFP_KERNEL);
+               kmalloc_array(count, sizeof(int), GFP_KERNEL);
        if (!subs->rate_list.list)
                return -ENOMEM;
        subs->rate_list.count = count;
index 0ddf29267d70fc8f10e68109b70fd6c6798ac856..da4a5a541512ddabba38d84565e2b98e1457fb3e 100644 (file)
@@ -266,7 +266,9 @@ int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y)
        int     err = 0,
                i;
 
-       if (NULL == (usX2Y->AS04.buffer = kmalloc(URB_DataLen_AsyncSeq*URBS_AsyncSeq, GFP_KERNEL))) {
+       usX2Y->AS04.buffer = kmalloc_array(URBS_AsyncSeq,
+                                          URB_DataLen_AsyncSeq, GFP_KERNEL);
+       if (NULL == usX2Y->AS04.buffer) {
                err = -ENOMEM;
        } else
                for (i = 0; i < URBS_AsyncSeq; ++i) {
index 345e439aa95b43dc237f8ca26032547b9115c422..2b833054e3b0d04236472e0df44ce2eef1a3fe97 100644 (file)
@@ -436,7 +436,9 @@ static int usX2Y_urbs_allocate(struct snd_usX2Y_substream *subs)
                }
                if (!is_playback && !(*purb)->transfer_buffer) {
                        /* allocate a capture buffer per urb */
-                       (*purb)->transfer_buffer = kmalloc(subs->maxpacksize * nr_of_packs(), GFP_KERNEL);
+                       (*purb)->transfer_buffer =
+                               kmalloc_array(subs->maxpacksize,
+                                             nr_of_packs(), GFP_KERNEL);
                        if (NULL == (*purb)->transfer_buffer) {
                                usX2Y_urbs_release(subs);
                                return -ENOMEM;
@@ -662,7 +664,8 @@ static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate)
                        err = -ENOMEM;
                        goto cleanup;
                }
-               usbdata = kmalloc(sizeof(int) * NOOF_SETRATE_URBS, GFP_KERNEL);
+               usbdata = kmalloc_array(NOOF_SETRATE_URBS, sizeof(int),
+                                       GFP_KERNEL);
                if (NULL == usbdata) {
                        err = -ENOMEM;
                        goto cleanup;