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 b9786f4..1df21a6 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 61e281c..a1606d9 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 9ed0129..14db141 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 94f8bf7..dfe40cb 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 46ecc5d..acf10eb 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 85d0951..d9b576d 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 fc482d9..24b0475 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 94058c2..6aa774a 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 9926ad6..1c18f29 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 96aaae6..81b2cbc 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 1d4e0ef..df062a1 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 dce87f1..cebf051 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 80e974a..d374f9b 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 feebb29..d63fb3c 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 920d408..6ad15d3 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 048ad78..8babbeb 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 7e49bbc..33e3517 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 3bd8ca9..a5ff886 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 dcf5ea2..83c4703 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 02168fe..627075e 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 784bc2d..6f8164d 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 6e461fb..5f4829f 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 b6be34e..ddccdea 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 8c1cc08..163ae70 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 950ec50..e831e6d 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 8fca446..2580cd2 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 0cc04e3..5579987 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 b96d382..ca446da 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 2a365c7..0417937 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 d1d9984..11e4535 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 2f2e737..f0b5226 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 9cb7411..b1e9f81 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 a651ab3..a303fd0 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 7f9aff4..fbc936c 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 0df1a1c..1728301 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 6bd2f65..7eebae7 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 6ca77d6..f651806 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 21e6d1b..d6b6f43 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 8f9130a..d0c5bc4 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 9adc8c3..a78b8e7 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 2053f70..52ffe17 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 fc8e1bc..31c374b 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 3051c73..e7d5bdc 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 79d8c84..31fcd04 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 4bf7c06..17084cf 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 1653151..56a4ebb 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 51fc682..00c7aab 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 981e456..cdc96f1 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 7a67b83..d91cbbe 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 1993889..4528b56 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 38c0aa6..051327a 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 60e75e6..82ba110 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 0ff36d4..ea79908 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 6ef9762..19dd665 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 f0c0d39..1db60aa 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 40e1e24..a580838 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 7171b74..237041a 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 358ac4f..ae08a1c 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 191832b..6b9c577 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 73e463e..dea444d 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 920b3d3..bbfde1c 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 401c02e..f92fe20 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 0faf042..3ea7168 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 c5716a0..771250a 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 2a5b846..35dc748 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 1ee6855..50a1d42 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 06c94e3..6e2d130 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 f63d99c..3f14c1c 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 71d44c3..1d34619 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 355dc7e..f858cc7 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 4f4e7a0..6d99534 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 7f965e2..864a084 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 b39844a..4a44e48 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 1667b6e..1aca742 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 56d7bc2..416a2f3 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 6813ee7..bff10ab 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 a0a9ed7..a077500 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 5c2cfde..724d232 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 f839bf3..4ec519a 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 cd2c08c..3b8045f 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 b4e0cf4..aaf10dd 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 419a2a2..83aa47e 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 6902017..30400ea 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 7a31be3..cc9c0c8 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 ed9a989..dc3c234 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 d21960c..af1c49d 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 d22f970..f79732b 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 007d5e8..61014e2 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 784ed6b..eb9f9e9 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 8a15e5c..fb1ff59 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 bdff232..163a57a 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 8414ae4..27155d9 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 ca858d6..2f63885 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 c35d2cd..9786b24 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 dfec0e1..3081c62 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 d1c6e48..7f4dff9 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 5416f2b..4e7ce74 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 7ac5179..ee510f9 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 56748af..fd13ed4 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 15482c5..76b5407 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 86b8217..3715fa0 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 14dada4..34d5999 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 b7f54fa..e932a15 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 7c6f3f5..1644ac5 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 491df0f..f497a77 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 fc68c7a..136e7e6 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 f745404..97de7a7 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 56059fb..21de30b 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 caa51dd..9387667 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 239c7bb..01c8329 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 0b344d0..e7c0ecd 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 1147ae5..e35db73 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 6a6be0b..74aff68 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 8e62b8b..b19058e 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 82ec216..5903101 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 b51fc37..a771e0a 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 d96236d..c4a84fb 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 ed9bcaf..19c6a03 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 0ae557c..4457829 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 72bd893..468f5cc 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 aa85fe3..96055de 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 0f5954a..f29d1be 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 b28c997..a88b2e5 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 2e5c346..78155f5 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 a15181f..716fc8e 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 4cbed4d..ebc00d4 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 34a5a41..59dc24b 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 0339538..b4d7774 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 f5695be..5a81bd8 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 7c889ec..22506d2 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 7b7658a..35aa72b 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 ef6ad25..1f8063c 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 2d59841..10d977e 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 5c5ba3c..b13557f 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 6b223cf..c5d4b65 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 6b86d1a..cbc5925 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 7161f8a..6593879 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 7f11b68..b7387ac 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 6281da3..27184e3 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 7963634..9d019ce 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 95f0bf9..7a1e545 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 e509f8a..0fe1217 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 edb1c83..b98481b 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 12a6a93..b56d84c 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 cfe86a2..28e9ae1 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 cb489e7..282ebdd 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 db4bcc5..bb41bec 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 3853296..e13bf3b 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 38f635c..05d4059 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 251d5bd..c301aaf 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 35cb3ae..3001d8e 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 a96b838..42fca32 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 c1b51ed..525d8b8 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 5d365a9..bdb3f8e 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 e084cb7..02ebf20 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 2d79849..0edd3cd 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 43744bf..c8c93ac 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 62f2173..43664ad 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 bdd179c..be2636e 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 6a9086d..03375c7 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 6f57c05..1f3372c 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 29e50f7..b0e1125 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 2e4effa..b34055a 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 66c665d..7cbd017 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 7cd4946..34a1581 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 6f9927d..4e0b443 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 70de062..353f1c1 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 f38e32a..ec629a7 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 f411164..029206e 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 8863fa0..ca0af0e 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 f4d7362..e95dd12 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 a6ef759..9e8ad37 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 d9eea8c..770aa62 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 1619ee3..15b9a83 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 641b13a..b1b8bc3 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 6343cc9..34e1009 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 6b37036..e60bea4 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 9d830d2..9fb0d9f 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 7e01981..1a18755 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 ce0fbf8..72046e1 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 7c4f550..b8fd3cc 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 f26beeb..8a858f7 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 de8a099..da8c30f 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 c1bc0a6..1ca9731 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 b01b44a..1f6d9f3 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 102646f..ac0672b 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 e582a21..8445376 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 5af89de..e7169ac 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 25e80a5..44459d2 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 fb2c359..0af8c52 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 1c98023..5b8af27 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 ed80d00..a9ae827 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 e7961cb..a9831bd 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 1242179..41add33 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 034f4ee..67d292d 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 2dbc833..35e0b5b 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 3441ce3..996dfe9 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 b3cfdd5..d981c16 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 097f37d..ea23c8d 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 3a9eca1..e6f31fa 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 4136166..0758edb 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 8c4d300..177701d 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 3b3767e..8e8cf11 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 bb802b0..8428247 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 2bbe797..773c4bf 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 872d66d..de2bc78 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 43f7358..d2b333d 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 592b6db..8332f95 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 c9e27e7..c16e4de 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 45d0463..6dc8891 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 ba3cfa8..a7e94a3 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 d2e13ff..906c354 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 37a610d..f2cdcc2 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 a4df95c..8b17400 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 1db1d97..cb4db1b 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 bdd3027..8d96e86 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 55b3eff..8e44287 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 722a669..7c7ada0 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 5d412df..d5b4a2b 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 7851383..90ea1cc 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 76e16c5..476dcc5 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 7b13700..1a15392 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 3a4e8f6..f3308ce 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 d3ee1f5..4f267dc 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 236a60f..c2e255f 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 62c91e3..2fb7130 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 900591d..6b8edf6 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 93cf57a..4d261e4 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 1cf7dbf..bc9da73 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 8c814b2..b8527c5 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 f3e2325..ad30ddf 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 a50cf45..c0430a4 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 e7cf7d2..686dc67 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 7ad5709..ce10eb7 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 906b8f0..4058985 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 f9bce81..ce8c95b 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 bb8971f..a94d700 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 790900d..ca935c0 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 3e330e0..c910e74 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 37a8b0b..dfa9a8a 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 1888f8c..ce08251 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 8a51e4d..c0d4452 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 f98eee2..1936afc 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 924d073..609438d 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 2b2d673..522cf44 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 ba82f97..c4eb866 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 fe92eed..8dd296d 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 418a2d0..2e50120 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 a582d3a..8a53d1d 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 ff82823..cc242ba 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 9b45125..52f577b 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 035ff6e..696106e 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 2f3856a..3093655 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 48d4d1c..a491d0e 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 21d464a..814b395 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 27be107..2473b0a 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 ee2c891..ea4a08b 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 ed4f851..a9ef46f 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 cfda2c7..71fa525 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 c332c95..238fd28 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 4ad6f66..bf5ee6f 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 d90993a..b53bb37 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 05e12ae..0dd87aa 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 5f7ad3d..c9cb2f3 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 5ece2e6..cf8d248 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 a3b5654..3d19595 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 13a8a77..1d377b7 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 745fd7f..a94071c 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 48e2004..af032e1 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 24887a0..1f1a68f 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 0ac6281..5f81fcd 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 c09289a..25ab127 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 d792b76..e5fb384 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 4f4362d..d4e23f8 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 e03ca14..c6b88fa 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 d9fb0ad..3090c44 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 097bd3c..4614ee2 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 e8585df..0efae7a 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 6bc5cfe..33abcf2 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 cf5c7f3..af0d5b0 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 a4ad18a..4ada525 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 7c49f1e..ecd9fcc 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 240779e..a1143e5 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 2cfe487..c6821a5 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 2d514c7..49263e2 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 de2bcb3..52bae3f 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 c7de6f5..0148e2e 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 bf41e2e..081ccf0 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 6df1f61..2490ddb 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 66eaeb1..9c247fa 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 fc74d6f..39370a5 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 f8eb043..fbd0090 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 e507618..1296f78 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 425081b..2acd58b 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 4aa9ce5..80aa425 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 597969d..e967901 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 e83bd97..153f8f6 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 23148c3..358ee2a 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 bc3cc0f..317891f 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 005d09c..2365ab0 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 9a51710..d4e45ad 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 6c397a3..c5466c7 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 ba3d0e0..4a21e7f 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 aa31f60..a9df94a 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 8254b8b..4880881 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 b4b5b81..1603492 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 e06c97f..9b3f9b0 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 b42037e..d8b12e0 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 e405677..aaa6953 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 1d5632d..5349c91 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 6850ffd..4ceeb13 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 c955b10..9f5326e 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 61a1125..05a8314 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 8d83bcf..df4b625 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 108ce3e..8ea8550 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 0171407..e1c818d 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 492c255..c3d7583 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 5c35752..1a19a0a 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 835242e..75509a1 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 b0f757b..015656a 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 314f4df..2dbfc4c 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 7d36c1e..b7055b2 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 dfcf542..d8bb1a1 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 06dad7a..1642fd5 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 ba8fdc0..1cd7c1a 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 696beff..3612fbb 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 1550547..faf5dcb 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 16e1068..931ea00 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 4d03722..05006cb 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 31e0dcb..75620c2 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 1dec337..ee8ef12 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 9b7907e..d17a473 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 97fedff..394ff1d 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 9645ffd..e22820e 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 a3d0adc..e560d39 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 6e18242..57b7bab 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 c15075d..436e4f9 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 d2f4e0c..2589a6b 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 385f153..2b75df4 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 bf4e4ad..6bcd1ea 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 4d2e797..fb1b1f9 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 8221bc5..7fadfbc 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 fb586b6..267ab9d 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 afdeca5..d88841f 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 b7df32a..46f9df9 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 ca4c4d9..cae4a02 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 df9ab71..d0d8397 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 b9ce82c..25eeb6d 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 a61818e..0f5ce77 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 140a44a..e367a97 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 6c0ae27..278ac08 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 11d9337..5dffbc4 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 9463af4..be8f103 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 4492cda..a2f7674 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 4237766..b69d3b1 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 39d853b..946ab08 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 04c6301..cecc797 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 9e2912e..288f839 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 ea15066..1ebf00c 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 8c0f8a9..fc9bcd4 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 ed1251c..146e1a3 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 c44eade..99d5a02 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 b45a01b..af1085d 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 08151f3..d91c87e 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 033aa84..c6b778b 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 3a1c0b8..c488c5a 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 8a69221..b13c868 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 8ca2e41..6f81396 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 f13ef33..9037a35 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 8d49522..108e8bf 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 fb1c1ea..f35d29f 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 49e7ec6..1f7a74a 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 b3854f8..72c6f8e 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 898afd3..8c3568d 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 78d1cad..160f52c 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 0ddf292..da4a5a5 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 345e439..2b83305 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;