Skip to content

Commit ad5eac8

Browse files
AttilaFueloeptonyhutter
authored andcommitted
gcc 11 cleanup
Compiling with gcc 11.1.0 produces three new warnings. Change the code slightly to avoid them. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Matthew Ahrens <[email protected]> Signed-off-by: Attila Fülöp <[email protected]> Closes #12130 Closes #12188 Closes #12237
1 parent 38cf8c0 commit ad5eac8

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

contrib/pam_zfs_key/pam_zfs_key.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ alloc_pw_size(size_t len)
8282
return (NULL);
8383
}
8484
pw->len = len;
85-
pw->value = malloc(len);
85+
/*
86+
* The use of malloc() triggers a spurious gcc 11 -Wmaybe-uninitialized
87+
* warning in the mlock() function call below, so use calloc().
88+
*/
89+
pw->value = calloc(len, 1);
8690
if (!pw->value) {
8791
free(pw);
8892
return (NULL);
@@ -99,7 +103,11 @@ alloc_pw_string(const char *source)
99103
return (NULL);
100104
}
101105
pw->len = strlen(source) + 1;
102-
pw->value = malloc(pw->len);
106+
/*
107+
* The use of malloc() triggers a spurious gcc 11 -Wmaybe-uninitialized
108+
* warning in the mlock() function call below, so use calloc().
109+
*/
110+
pw->value = calloc(pw->len, 1);
103111
if (!pw->value) {
104112
free(pw);
105113
return (NULL);

include/sys/crypto/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct {
5858
*/
5959

6060
#define CRYPTO_MECH_INVALID ((uint64_t)-1)
61-
extern crypto_mech_type_t crypto_mech2id(crypto_mech_name_t name);
61+
extern crypto_mech_type_t crypto_mech2id(char *name);
6262

6363
/*
6464
* Create and destroy context templates.

include/sys/dnode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ enum dnode_dirtycontext {
171171
* example, reading 32 dnodes from a 16k dnode block and all of the spill
172172
* blocks could issue 33 separate reads. Now suppose those dnodes have size
173173
* 1024 and therefore don't need spill blocks. Then the worst case number
174-
* of blocks read is reduced to from 33 to two--one per dnode block.
174+
* of blocks read is reduced from 33 to two--one per dnode block.
175175
*
176176
* ZFS-on-Linux systems that make heavy use of extended attributes benefit
177177
* from this feature. In particular, ZFS-on-Linux supports the xattr=sa
@@ -232,8 +232,8 @@ typedef struct dnode_phys {
232232
* Both dn_pad2 and dn_pad3 are protected by the block's MAC. This
233233
* allows us to protect any fields that might be added here in the
234234
* future. In either case, developers will want to check
235-
* zio_crypt_init_uios_dnode() to ensure the new field is being
236-
* protected properly.
235+
* zio_crypt_init_uios_dnode() and zio_crypt_do_dnode_hmac_updates()
236+
* to ensure the new field is being protected and updated properly.
237237
*/
238238
uint64_t dn_pad3[4];
239239

module/os/linux/zfs/zio_crypt.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ unsigned long zfs_key_max_salt_uses = ZFS_KEY_MAX_SALT_USES_DEFAULT;
190190

191191
typedef struct blkptr_auth_buf {
192192
uint64_t bab_prop; /* blk_prop - portable mask */
193-
uint8_t bab_mac[ZIO_DATA_MAC_LEN]; /* MAC from blk_cksum */
193+
uint8_t bab_mac[ZIO_DATA_MAC_LEN]; /* MAC from blk_cksum */
194194
uint64_t bab_pad; /* reserved for future use */
195195
} blkptr_auth_buf_t;
196196

@@ -1045,17 +1045,23 @@ zio_crypt_do_dnode_hmac_updates(crypto_context_t ctx, uint64_t version,
10451045
boolean_t should_bswap, dnode_phys_t *dnp)
10461046
{
10471047
int ret, i;
1048-
dnode_phys_t *adnp;
1048+
dnode_phys_t *adnp, tmp_dncore;
1049+
size_t dn_core_size = offsetof(dnode_phys_t, dn_blkptr);
10491050
boolean_t le_bswap = (should_bswap == ZFS_HOST_BYTEORDER);
10501051
crypto_data_t cd;
1051-
uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)];
10521052

10531053
cd.cd_format = CRYPTO_DATA_RAW;
10541054
cd.cd_offset = 0;
10551055

1056-
/* authenticate the core dnode (masking out non-portable bits) */
1057-
bcopy(dnp, tmp_dncore, sizeof (tmp_dncore));
1058-
adnp = (dnode_phys_t *)tmp_dncore;
1056+
/*
1057+
* Authenticate the core dnode (masking out non-portable bits).
1058+
* We only copy the first 64 bytes we operate on to avoid the overhead
1059+
* of copying 512-64 unneeded bytes. The compiler seems to be fine
1060+
* with that.
1061+
*/
1062+
bcopy(dnp, &tmp_dncore, dn_core_size);
1063+
adnp = &tmp_dncore;
1064+
10591065
if (le_bswap) {
10601066
adnp->dn_datablkszsec = BSWAP_16(adnp->dn_datablkszsec);
10611067
adnp->dn_bonuslen = BSWAP_16(adnp->dn_bonuslen);
@@ -1065,7 +1071,7 @@ zio_crypt_do_dnode_hmac_updates(crypto_context_t ctx, uint64_t version,
10651071
adnp->dn_flags &= DNODE_CRYPT_PORTABLE_FLAGS_MASK;
10661072
adnp->dn_used = 0;
10671073

1068-
cd.cd_length = sizeof (tmp_dncore);
1074+
cd.cd_length = dn_core_size;
10691075
cd.cd_raw.iov_base = (char *)adnp;
10701076
cd.cd_raw.iov_len = cd.cd_length;
10711077

0 commit comments

Comments
 (0)