From nobody Fri Jan 26 21:05:09 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TM9FL0Js9z58qdy; Fri, 26 Jan 2024 21:05:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TM9FK69nMz4NcL; Fri, 26 Jan 2024 21:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706303109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6EvCdY6LX/LDH8gH/pqtGEGWJGh0k/E6E8+2Vwm05iY=; b=EVz0Ib6mAUo2dlP2xzaAb7joYbq+hm+pb3KUOeTzYzLNXitF4Y2r+TeW63XoX+AdOGiVQy Zk6+ExMx7HfHa4qSiVWoGfIqGf7Zlz0T9Py6UzS/VAUSQYGZgGQPIxijZHeOo3d5Qh+/5t e/BaNXQhExFx9UvVdyDpzEXQeK/Cy2s9TmUcreWESgjfbhppt9+tPZSGauyjImkZXaed4l /gk0SCwRlWxbbYYgPtwleXNEFhbA167IPxAsWEqTkN1KiGxgYECWpJw0oQgDpHsemoSYH4 TxgyldfIzTzmaDTHwiRR80UGSh+J3zHSQqY9IZR35fIul6alaAb8I8nBgOjFsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706303109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6EvCdY6LX/LDH8gH/pqtGEGWJGh0k/E6E8+2Vwm05iY=; b=DMZMfmUre1x4LsBWIG5ruTNFg//qRRDUQyzECZVWrY+UNktfAuAlvkziz1AQSnOTZdNnXw pB6HOp2P7xR66a4HrFtwG3y+XMnsbtct0brHQo2Te9uufERJphmqXiJ7kw0DklahTtrTzz h0s4ek7UWxie2dWDrRqliVks+w6O8XnIbht5M/3e9cjbK1oVtWZKvnCaiyl08zldHEX4WE 1+qr/pyU/wLBqwbdMrLf31Q/e66MxKRmZLdKq2V74k2IdtQB4GDtbobMk71Y2vMCWvaO14 ClV++6sDz3tDWin5Tucgd2NKVQETf1iJrarp9XUXKgCaa/tOjvQprb5oOlI1Fg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706303109; a=rsa-sha256; cv=none; b=hv7Cj4OJ+l+bMxUaYfh6nJ2Ug1uiYLdPHqu41fVo1xwaGsUs2BVAkB8xEzyJPf6GCJCFfT PcrxVJfobKnUNT0BG79OQ0n9c+FwnMInyUhKecgeFSO2qM1Q95N0IzE7jQyPKYvcFVatT9 ZSe2I94V1XLHCvYUbiq/9/YFfwT5PB+mczw9kWvjVteEjLsfNMCmsJoxZXRMuZEZssywmI ei80oACcmBZdleH3u+L8TdRuX2deROGnQI8nooHCyiCGe4yMp4Bo1SkMNmlJE3TpFqK/j5 6Rlszaw8y8+1JKZvGKpvwd9Yw05msZCK+R1EFAobkpOhWiYRf+7m3122B0TmFg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TM9FK5GZLzxZs; Fri, 26 Jan 2024 21:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40QL59cI084359; Fri, 26 Jan 2024 21:05:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40QL59Np084356; Fri, 26 Jan 2024 21:05:09 GMT (envelope-from git) Date: Fri, 26 Jan 2024 21:05:09 GMT Message-Id: <202401262105.40QL59Np084356@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 8bd4bf5db4c3 - stable/13 - libthr: thr_attr.c: More style and clarity fixes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8bd4bf5db4c3de931bd18c5b57ca98cd9c980ede Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=8bd4bf5db4c3de931bd18c5b57ca98cd9c980ede commit 8bd4bf5db4c3de931bd18c5b57ca98cd9c980ede Author: Olivier Certner AuthorDate: 2024-01-04 15:10:40 +0000 Commit: Olivier Certner CommitDate: 2024-01-26 21:04:20 +0000 libthr: thr_attr.c: More style and clarity fixes The change of argument for sizeof() (from a type to an object) is to be consistent with the change done for the malloc() code just above in the preceding commit touching this file. Consider bit flags as integers and test whether they are set with an explicit comparison with 0. Use an explicit flag value (PTHREAD_SCOPE_SYSTEM) in place of a variable that has this value at point of substitution. All other changes are straightforward. Suggested by: kib Reviewed by: kib Approved by: emaste (mentor) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43327 (cherry picked from commit 4d312aa051414ad77d3515f258230d01ad11d6dc) Approved by: markj (mentor) --- lib/libthr/thread/thr_attr.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c index 0ccc31b22c13..bbb143da1a7d 100644 --- a/lib/libthr/thread/thr_attr.c +++ b/lib/libthr/thread/thr_attr.c @@ -117,8 +117,7 @@ _thr_attr_destroy(pthread_attr_t *attr) if (attr == NULL || *attr == NULL) return (EINVAL); - if ((*attr)->cpuset != NULL) - free((*attr)->cpuset); + free((*attr)->cpuset); free(*attr); *attr = NULL; return (0); @@ -151,7 +150,7 @@ _thr_attr_get_np(pthread_t pthread, pthread_attr_t *dstattr) return (error); attr = pthread->attr; - if (pthread->flags & THR_FLAGS_DETACHED) + if ((pthread->flags & THR_FLAGS_DETACHED) != 0) attr.flags |= PTHREAD_DETACHED; error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, TID(pthread), @@ -180,7 +179,7 @@ _thr_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) if (attr == NULL || *attr == NULL || detachstate == NULL) return (EINVAL); - if ((*attr)->flags & PTHREAD_DETACHED) + if (((*attr)->flags & PTHREAD_DETACHED) != 0) *detachstate = PTHREAD_CREATE_DETACHED; else *detachstate = PTHREAD_CREATE_JOINABLE; @@ -258,7 +257,7 @@ _thr_attr_getscope(const pthread_attr_t * __restrict attr, if (attr == NULL || *attr == NULL || contentionscope == NULL) return (EINVAL); - *contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ? + *contentionscope = ((*attr)->flags & PTHREAD_SCOPE_SYSTEM) != 0 ? PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS; return (0); } @@ -321,7 +320,7 @@ _thr_attr_init(pthread_attr_t *attr) if ((pattr = malloc(sizeof(*pattr))) == NULL) return (ENOMEM); - memcpy(pattr, &_pthread_attr_default, sizeof(struct pthread_attr)); + memcpy(pattr, &_pthread_attr_default, sizeof(*pattr)); *attr = pattr; return (0); } @@ -449,7 +448,7 @@ _thr_attr_setscope(pthread_attr_t *attr, int contentionscope) return (EINVAL); if (contentionscope == PTHREAD_SCOPE_SYSTEM) - (*attr)->flags |= contentionscope; + (*attr)->flags |= PTHREAD_SCOPE_SYSTEM; else (*attr)->flags &= ~PTHREAD_SCOPE_SYSTEM; return (0); @@ -546,6 +545,7 @@ _pthread_attr_setaffinity_np(pthread_attr_t *pattr, size_t cpusetsize, if (cpusetsize > kern_size) { /* Kernel checks invalid bits, we check it here too. */ size_t i; + for (i = kern_size; i < cpusetsize; ++i) if (((const char *)cpusetp)[i] != 0) return (EINVAL);