@@ -1476,22 +1476,20 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
14761476}
14771477EXPORT_SYMBOL_GPL (inet_ctl_sock_create );
14781478
1479- unsigned long snmp_fold_field (void __percpu * mib [] , int offt )
1479+ unsigned long snmp_fold_field (void __percpu * mib , int offt )
14801480{
14811481 unsigned long res = 0 ;
1482- int i , j ;
1482+ int i ;
14831483
1484- for_each_possible_cpu (i ) {
1485- for (j = 0 ; j < SNMP_ARRAY_SZ ; j ++ )
1486- res += * (((unsigned long * ) per_cpu_ptr (mib [j ], i )) + offt );
1487- }
1484+ for_each_possible_cpu (i )
1485+ res += * (((unsigned long * ) per_cpu_ptr (mib , i )) + offt );
14881486 return res ;
14891487}
14901488EXPORT_SYMBOL_GPL (snmp_fold_field );
14911489
14921490#if BITS_PER_LONG == 32
14931491
1494- u64 snmp_fold_field64 (void __percpu * mib [] , int offt , size_t syncp_offset )
1492+ u64 snmp_fold_field64 (void __percpu * mib , int offt , size_t syncp_offset )
14951493{
14961494 u64 res = 0 ;
14971495 int cpu ;
@@ -1502,7 +1500,7 @@ u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_offset)
15021500 u64 v ;
15031501 unsigned int start ;
15041502
1505- bhptr = per_cpu_ptr (mib [ 0 ] , cpu );
1503+ bhptr = per_cpu_ptr (mib , cpu );
15061504 syncp = (struct u64_stats_sync * )(bhptr + syncp_offset );
15071505 do {
15081506 start = u64_stats_fetch_begin_irq (syncp );
@@ -1516,25 +1514,6 @@ u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_offset)
15161514EXPORT_SYMBOL_GPL (snmp_fold_field64 );
15171515#endif
15181516
1519- int snmp_mib_init (void __percpu * ptr [2 ], size_t mibsize , size_t align )
1520- {
1521- BUG_ON (ptr == NULL );
1522- ptr [0 ] = __alloc_percpu (mibsize , align );
1523- if (!ptr [0 ])
1524- return - ENOMEM ;
1525-
1526- #if SNMP_ARRAY_SZ == 2
1527- ptr [1 ] = __alloc_percpu (mibsize , align );
1528- if (!ptr [1 ]) {
1529- free_percpu (ptr [0 ]);
1530- ptr [0 ] = NULL ;
1531- return - ENOMEM ;
1532- }
1533- #endif
1534- return 0 ;
1535- }
1536- EXPORT_SYMBOL_GPL (snmp_mib_init );
1537-
15381517#ifdef CONFIG_IP_MULTICAST
15391518static const struct net_protocol igmp_protocol = {
15401519 .handler = igmp_rcv ,
@@ -1570,40 +1549,30 @@ static __net_init int ipv4_mib_init_net(struct net *net)
15701549{
15711550 int i ;
15721551
1573- if (snmp_mib_init ((void __percpu * * )net -> mib .tcp_statistics ,
1574- sizeof (struct tcp_mib ),
1575- __alignof__(struct tcp_mib )) < 0 )
1552+ net -> mib .tcp_statistics = alloc_percpu (struct tcp_mib );
1553+ if (!net -> mib .tcp_statistics )
15761554 goto err_tcp_mib ;
1577- if (snmp_mib_init ((void __percpu * * )net -> mib .ip_statistics ,
1578- sizeof (struct ipstats_mib ),
1579- __alignof__(struct ipstats_mib )) < 0 )
1555+ net -> mib .ip_statistics = alloc_percpu (struct ipstats_mib );
1556+ if (!net -> mib .ip_statistics )
15801557 goto err_ip_mib ;
15811558
15821559 for_each_possible_cpu (i ) {
15831560 struct ipstats_mib * af_inet_stats ;
1584- af_inet_stats = per_cpu_ptr (net -> mib .ip_statistics [ 0 ] , i );
1561+ af_inet_stats = per_cpu_ptr (net -> mib .ip_statistics , i );
15851562 u64_stats_init (& af_inet_stats -> syncp );
1586- #if SNMP_ARRAY_SZ == 2
1587- af_inet_stats = per_cpu_ptr (net -> mib .ip_statistics [1 ], i );
1588- u64_stats_init (& af_inet_stats -> syncp );
1589- #endif
15901563 }
15911564
1592- if (snmp_mib_init ((void __percpu * * )net -> mib .net_statistics ,
1593- sizeof (struct linux_mib ),
1594- __alignof__(struct linux_mib )) < 0 )
1565+ net -> mib .net_statistics = alloc_percpu (struct linux_mib );
1566+ if (!net -> mib .net_statistics )
15951567 goto err_net_mib ;
1596- if (snmp_mib_init ((void __percpu * * )net -> mib .udp_statistics ,
1597- sizeof (struct udp_mib ),
1598- __alignof__(struct udp_mib )) < 0 )
1568+ net -> mib .udp_statistics = alloc_percpu (struct udp_mib );
1569+ if (!net -> mib .udp_statistics )
15991570 goto err_udp_mib ;
1600- if (snmp_mib_init ((void __percpu * * )net -> mib .udplite_statistics ,
1601- sizeof (struct udp_mib ),
1602- __alignof__(struct udp_mib )) < 0 )
1571+ net -> mib .udplite_statistics = alloc_percpu (struct udp_mib );
1572+ if (!net -> mib .udplite_statistics )
16031573 goto err_udplite_mib ;
1604- if (snmp_mib_init ((void __percpu * * )net -> mib .icmp_statistics ,
1605- sizeof (struct icmp_mib ),
1606- __alignof__(struct icmp_mib )) < 0 )
1574+ net -> mib .icmp_statistics = alloc_percpu (struct icmp_mib );
1575+ if (!net -> mib .icmp_statistics )
16071576 goto err_icmp_mib ;
16081577 net -> mib .icmpmsg_statistics = kzalloc (sizeof (struct icmpmsg_mib ),
16091578 GFP_KERNEL );
@@ -1614,30 +1583,30 @@ static __net_init int ipv4_mib_init_net(struct net *net)
16141583 return 0 ;
16151584
16161585err_icmpmsg_mib :
1617- snmp_mib_free (( void __percpu * * ) net -> mib .icmp_statistics );
1586+ free_percpu ( net -> mib .icmp_statistics );
16181587err_icmp_mib :
1619- snmp_mib_free (( void __percpu * * ) net -> mib .udplite_statistics );
1588+ free_percpu ( net -> mib .udplite_statistics );
16201589err_udplite_mib :
1621- snmp_mib_free (( void __percpu * * ) net -> mib .udp_statistics );
1590+ free_percpu ( net -> mib .udp_statistics );
16221591err_udp_mib :
1623- snmp_mib_free (( void __percpu * * ) net -> mib .net_statistics );
1592+ free_percpu ( net -> mib .net_statistics );
16241593err_net_mib :
1625- snmp_mib_free (( void __percpu * * ) net -> mib .ip_statistics );
1594+ free_percpu ( net -> mib .ip_statistics );
16261595err_ip_mib :
1627- snmp_mib_free (( void __percpu * * ) net -> mib .tcp_statistics );
1596+ free_percpu ( net -> mib .tcp_statistics );
16281597err_tcp_mib :
16291598 return - ENOMEM ;
16301599}
16311600
16321601static __net_exit void ipv4_mib_exit_net (struct net * net )
16331602{
16341603 kfree (net -> mib .icmpmsg_statistics );
1635- snmp_mib_free (( void __percpu * * ) net -> mib .icmp_statistics );
1636- snmp_mib_free (( void __percpu * * ) net -> mib .udplite_statistics );
1637- snmp_mib_free (( void __percpu * * ) net -> mib .udp_statistics );
1638- snmp_mib_free (( void __percpu * * ) net -> mib .net_statistics );
1639- snmp_mib_free (( void __percpu * * ) net -> mib .ip_statistics );
1640- snmp_mib_free (( void __percpu * * ) net -> mib .tcp_statistics );
1604+ free_percpu ( net -> mib .icmp_statistics );
1605+ free_percpu ( net -> mib .udplite_statistics );
1606+ free_percpu ( net -> mib .udp_statistics );
1607+ free_percpu ( net -> mib .net_statistics );
1608+ free_percpu ( net -> mib .ip_statistics );
1609+ free_percpu ( net -> mib .tcp_statistics );
16411610}
16421611
16431612static __net_initdata struct pernet_operations ipv4_mib_ops = {
0 commit comments